I'm having trouble getting regular expressions with leading / trailing $'s to match in Java (1.6.20).
From this code:
System.out.println( "$40".matches("\\b\\Q$40\\E\\b") );
System.out.println( "$40".matches(".*\\Q$40\\E.*") );
System.out.println( "$40".matches("\\Q$40\\E") );
System.out.println( " ------ " );
System.out.println( "40$".matches("\\b\\Q40$\\E\\b") );
System.out.println( "40$".matches(".*\\Q40$\\E.*") );
System.out.println( "40$".matches("\\Q40$\\E") );
System.out.println( " ------ " );
System.out.println( "4$0".matches("\\b\\Q4$0\\E\\b") );
System.out.println( "40".matches("\\b\\Q40\\E\\b") );
I get these results:
false
true
true
------
false
true
true
------
true
true
The leading false in the first two blocks seem to be the problem. That is, the leading/trailing $ (dollar sign) is not picked up properly in the context of the \b (word boundary) marker.
The true results in the blocks show it's not the quoted dollar sign itself, since replacing the \b with a .* or removing all together get the desired result.
The last two "true" results show that the issue is neither with an internally quoted $ nor with matching on word boundaries (\b) within quoted expression "\Q ... \E".
Is this a Java bug or am I missing something?