Javascript regex to match person's height
If you want to make sure no one is cheating with it, you can limit it to reasonable ranges, for example: 3 'to 7'11' '
/^(3-7)'(?:\s*(?:1[01]|0-9)(''|"))?$/
I always assumed that the "inches" mark was a double quote ( "
) compared to VonC's answer where he put this as two single quotes ( ''
), so this regex counts both values.
source to share
Something like:
\d'(?:\s*\d+'')?
The second part refers to the optional part of the vertex.
Remove the + if you only want one digit.
\b\d'(?:\s*\d+'')?\b
can also be used to detect this pattern in text (avoid detecting 1234'45 as a top for ... face ?!)
You can check this regexp here for javascript .
source to share
Ok. Thanks for all your answers. Wow, that was fast. Great time.
Anyway, I've checked all of your regexes, and it seems that Ruben's answer went through all of my test input. Thanks a lot for this helper.
So, here's what I need:
^ (\ d {1,5}) \ '((\ s) (-) (\ S) ([0-9] | ?? (1 [0-1])) \ ")? $
^\d'\s?(\d{1,2}")?$
Tested here: http://www.regular-expressions.info/javascriptexample.html
source to share