I have been reading the regex questions on this site but my issue seems to be a bit different. I need to match a 2 digit number, such as 23 through 75. I am doing this on an HP-UX Unix system. I found examples of 3 - 44 but or any digit number, nothing that is fixed in length, which is a bit surprising, but perhaps I am not understand the variable length example answer.
相关问题
- Improve converting string to readable urls
- Regex to match charset
- Regex subsequence matching
- Accommodate two types of quotes in a regex
- Set together letters and numbers that are ordinal
相关文章
- Optimization techniques for backtracking regex imp
- Regex to check for new line
- Allow only 2 decimal points entry to a textbox usi
- Comparing speed of non-matching regexp
- Regular expression to get URL in string swift with
- 请问如何删除之前和之后的非字母中文单字
- Lazy (ungreedy) matching multiple groups using reg
- when [:punct:] is too much [duplicate]
Since you're not indicating whether this is in addition to any other characters (or in the middle of a larger string), I've included the logic here to indicate what you would need to match the number portion of a string. This should get you there. We're creating a range for the second numbers we're looking for only allowing those characters. Then we're comparing it to the other ranges as an
or
:As oded noted you can do this as well since sub ranges are also accepted (depends on the implementation of REGEX in the application you're using):
Based on the title you would change the last 5 to a 9 to go from 75-79:
If you are trying to match these numbers specifically as a string (from start to end) then you would use the modifiers
^
and$
to indicate the beginning and end of the string.There is an excellent technical reference of Regex ranges here:
http://www.regular-expressions.info/numericranges.html
If you're using something like grep and trying to match lines that contain the number with other content then you might do something like this for ranges thru 79:
This tool is exactly what you need:
Regex_For_RangeFrom 29 to 79:
\b(2[3-9]|[3-7][0-9])\b
From 29 to 75:
\b(29|[3-6][0-9]|7[0-5])\b
And just for fun, from 192 to 1742:
\b(19[2-9]|[2-9][0-9]{2}|1[0-6][0-9]{2}|17[0-3][0-9]|174[0-2])\b
:)You have two classes of numbers you want to match:
Edit: Well, that's the title's range (23-79). Within your question (23-75), you have three:
This should do it:
^
and$
will make it strict that it will match only 2 numbers, so in case that you havei.e 234
it won't work.If I want 2 digit range 0-63
This way you can take Regular Expression for any Two Digit Range