Learning regex but this one gives me a headache. I need to match a float number (with either . or , as decimal point) and it MUST end with the following characters: €/g.
Valid matches should be for example:
40€/g43.33€/g40,2€/g40.2€/g38.943€/g
Appreciate help..
The regex will look like:
In Javascript, as a regex object (note that the forward slash needs to be escaped):
Here’s a breakdown of what each part does:
If you want to allow something like .123€/g to be valid as well, you can use:
That is, both the groups of digits are optional, but at least one must be present (this uses lookahead, which is a bit more tricky).
Note that this will also match constructions like ‘word2€/g’. If you want to prevent this, start the regex with
(?<=^|\s)(matches if preceded by a space or the start of the string) and end it with(?=$|\s)(matches if followed by a space or the end of the string).Full-blown version: