I want to cut text from a string using regular expressions.
I use a regular expression:
(([0-9]+)\s+метров|([0-9]+)м)
If they process the line "Типа 10 метров"
, it cuts "10 метров"
, not "10"
PS I use the group()
method
I want to cut text from a string using regular expressions.
I use a regular expression:
(([0-9]+)\s+метров|([0-9]+)м)
If they process the line "Типа 10 метров"
, it cuts "10 метров"
, not "10"
PS I use the group()
method
I would use positive lookahead.
For php, this option will work (it did not work with java):
/(\d+)(?=м\b|\s+метров)/
Test https://regex101.com/r/sH6dD9/2
PS Both a complete match and the first group contain only numbers.
Rewrite the request in this form:
([0-9]+)(\s+метров|м)
Source: https://ru.stackoverflow.com/questions/545918/
All Articles