I've got a string that may or may not contain a number of 4 or 5 digits. I'm looking for a regex that can detect if the string does in fact have such a number.
\d works okay in .Net, too.
Joel Coehoorn
2009-04-03 13:04:47
Right. I'm not much of a Regexp guy, so I don't remember character classes. [0-9] is easier. :D
Vilx-
2009-04-03 13:29:02
+2
A:
\d{4,5} will also find strings with 6 digit numbers in - I don't know whether that's a problem or not. You might want to do something like this:
([^\d]+|^)\d{4,5}[^\d]
Will Dean
2009-04-03 13:09:07
+4
A:
The foolproof one to avoid longer numbers would be:
([^\d]|^)\d{4,5}([^\d]|$)
I'm assuming you don't want to allow for a comma after the thousands digit? If you do then:
([^\d]|^)\d{1,2},\d{3}([^\d]|$)
David M
2009-04-03 13:12:52