Reputation: 105
I'm having some difficulties with the regex boundary \b
character. I need to search for an exact keyword inside some loaded text(either plain textual data or Xml). Because the need for exact matches I use the \bkeyword\b
pattern but I get a different behaviour than what I expect when the keyword starts with a special character. For example the pattern \b€ 3,5\b
doesn't match in I have € 3,5 to spend!
. This is the case with any special characters.
I've search around but came up with no solution. Is there some mechanism that acts like a \b
but for special characters ? Also note that i cannot alter the keyword.
Any help would be appreciated.
Upvotes: 0
Views: 730
Reputation: 71548
You can perhaps make use of a positive lookbehind:
(?<=^|\s)€ 3,5\b
The positive lookbehind will match either the beginning of the string or a \s
, without including them in the match itself.
Upvotes: 1