The question is straight forward. I have some numbers, and I try to match numbers in range from 0 to 110. Let's say we have five numbers:
99.9
108.712718
110
110.2
9
Here I need to match all except fourth. I tried a lot. Capturing group, positive/negative lookahead and so on. Nothing works for me. It's easy without floating point, but here I struggling so much.
P.S. I' doing it with Python.
Something like this should work:
(?<!\.)\b0*(?:(?:\d\d?|10\d)(?:\.\d+)?|110(?:\.0+)?)\b(?!\.\d)
(?<!\.)
means "not preceded by a dot (\.
)"\b
is the word boundary0*
means "preceded by zero or more 0
"(\d\d?|10\d)
means "one digit followed by another optional digit (\d\d?
) or 10
followed by any digit"(\.\d+)?
)110
with one or more 0 after a dot ((?:\.0+)?
)(?!\.\d)
, which means "not followed by a dot and a digit"See here a demo.
P.S. If you are matching the correspondence of the whole string, negative lookahead and lookbehind are useless.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments