Does anyone know what format the regular expression would be if i wanted to limit input to betting odds format, ie x/y where x and y are positive integers. I Just cant get my head round how you format these things.
Does anyone know what format the regular expression would be if i wanted to limit input to betting odds format, ie x/y where x and y are positive integers. I Just cant get my head round how you format these things.
If you want to get the hang of regular expressions quickly a book that really helped me out is called "Regular Expression Pocket Reference". Well worth the £5 or so it costs.
The slashes were added to demonstrate the need to escape the middle slash, should the language chosen require delimiters and said delimiters be slashes.
/^(?:[1-9]\d*)+\/(?:[1-9]\d*)+$/ seems overly complex to me.
My example does, I believe, what was asked for - no more, no less.
Here it is again with explanatory notes.
^[1-9]\d*\/[1-9]\d*$
* [Assert position at the beginning of the string][1] `^`
* [Match a single character in the range between “1” and “9”][2] `[1-9]`
* [Match a single character that is a “digit” (any decimal number in any Unicode script)][3] `\d*`
* [Between zero and unlimited times, as many times as possible, giving back as needed (greedy)][4] `*`
* [Match the character “/” literally][5] `\/`
* [Match a single character in the range between “1” and “9”][2] `[1-9]`
* [Match a single character that is a “digit” (any decimal number in any Unicode script)][3] `\d*`
* [Between zero and unlimited times, as many times as possible, giving back as needed (greedy)][4] `*`
* [Assert position at the end of the string, or before the line break at the end of the string, if any (line feed)][1] `$`
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.