19 Aug 2016
I don't know about you, but I find regluar expressions quite difficult. Apart from a very simple, I almost always have to look it up or use a reference book.
Yesterday, one of my colleagues needed a regex for filtering on Google Analytics. The value needed to be greater than 1200 to be valid.
In case you are looking for a regex for something similar, I though I would post it so you can alter it for your needs.
^[1-9][2-9](?!00$)[0-9][1-9]?\d+$
I used this tool to test it.
And this is the tool's English interpretation of what the regex is doing:
The key part to this is the look aheadĀ (?!00$), this makes sure that it won't end with 00 after the first 2 digits. Without this in there, it would say 1200 is valid, which violates the rule of greater than
Anyway, I hope someone finds this useful one day. Or me 6 months time when I've forgotten and need something similar.