\b doesn't match when the preceding character is a word boundary

salsSpuctutle

New Member
I have a rather peculiar problem. I'm trying to find a pattern like \[code\][some string][word boundary]\[/code\]. Simplified, my code is:\[code\]final Pattern pattern = Pattern.compile(Pattern.quote(someString) + "\\b");final String value = http://stackoverflow.com/questions/11329821/someString +" ";System.out.println(pattern.matcher(value).find());\[/code\]My logic tells me this should always output \[code\]true\[/code\], regardless of what \[code\]someString\[/code\] is. However:
  • if \[code\]someString\[/code\] ends with a word character (e.g. "abc"), \[code\]true\[/code\] is outputted;
  • if \[code\]someString\[/code\] ends with a word boundary (e.g. "abc."), \[code\]false\[/code\] is outputted.
Any ideas what is happening? My current workaround is to use \[code\]\W\[/code\] instead of \[code\]\b\[/code\], but I'm not sure of the implications.
 
Top