Reputation: 564
I am trying to write a regular expression for checking if there is an exact price in a string.
The regex I had created that worked for the exact situation was
.*?0,00
As I am trying to capture when a price is exactly EUR 0,00.
But I am running into issues with prices like EUR 60,00, etc, as it is still matching the 0.00.
How would I create a regular expression to match exactly 0,00?
Upvotes: 0
Views: 63
Reputation: 163277
Your pattern .*?0,00
does not contain boundaries and will match any char except a newline 0+ times non greedy followed by matching 0,00
You could make use of word boundaries \b
\b0,00\b
Or if a negative lookahead and lookbehind is supported, you could assert what is on the left and on the right is not a non whitespace char \S
to not get a partial match in ,0,00,
(?<!\S)0,00(?!\S)
Upvotes: 1