I want a RegEx
to match distance values in metric system. This regex should match 12m
, 100cm
,1km
ignoring white space
相关问题
- 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]
And to extend Paul's answer to include decimal place values...
As you didn't specify exactly what you wanted, I used your examples to derive that you want find an integer value, followed by optional whitespace, followed by a unit specifier of cm, m or km. So - this is the simplest example of that.
The first parentheses captures the number, then it skips 0-many whitespace chars before capturing your required units in the second set of parentheses.
As you can see in other answers, you can go beyond this to pick up decimal values, and also capture a wider number of SI unit prefixes too.
Try this: