|
|
|
[
Permlink
| « Hide
]
Antti Karanta - 27/Dec/07 04:19 AM
Damn, the regex did not seem to come through. I'll try again:
This is expected behavior. Inside a slashy string, backslashes don't escape anything except a forward slash. So your string isn't terminated, hence the compilation exception. I would probably write it something like this:
def bs = '\\\\' // double escaped def fs = '/' assert 'foo/bar' =~ /$fs|$bs/ You are right, now I have it working. Thanks.
I find it a little strange that this worked fine on older groovy versions. I suppose there was some good reason for breaking it? If I got it right, there is now no way of matching a literal backslash in a regex short of creating the escaped backslash string outside the regex and then using gstring functionality to insert it into the regex (like it's done above)? A little annoying, IMO. Is this documented on some gotchas list? Yes, a little annoying but the old behavior had a much bigger set of gotcha rules. You could never place an odd number of consecutive backslashes into a slashy string. This was usually fine for regex scenarios but made windows path name and other scenarios a nightmare.
I'd be happy to have a look at what you wrote about this in the docs, but I can't find it. Where did you put it?
And I overstated the effect this has - it's not possible to insert a backslash as the last character in a slashy string, in other positions it's fine (just saying this out loud in case someone else reads this bug report). Docs went here:
http://groovy.codehaus.org/Strings#Strings-SlashyStringliterals I think the addition you made to the docs makes this very clear. I have nothing to add to that.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||