Regular Expression for even number

Posted by Marcus Hammarberg on November 3, 2008
Stats

Let me first be very clear - I'm not a RegExp-guy. I find them quite hard to understand at times and often take my refuge to the .NET-code.

Also I was very surprised to not find any hits for the search of "RegExp even numbers" - I thought that I would find numerous examples.

But after reading a bit at this place I learned enough to create my first own, naïve regular expression - a regular expression to allow only even numbers:

^\d*?((0)|(2)|(4)|(6)|(8))$ 

Again - my apologies for being a newbie on this... but hey it works.

I also found this resource very useful for trying my expression out.

Regular Expressions are very powerful but "with great powers comes great responsibilities"... that is they are often hard to understand.

Thanks Fredrik S for the links.



Published by Marcus Hammarberg on Last updated