python - Need regex for a period that's not between numbers -
need regex periods that's not between 2 numbers
it should match
happy1...
hello, world.
but should not match:
- 1.2
- holiday
this work you:
((?<!\d)\.|\.(?!\d)) it matches period isn't preceded digit ((?<!\d)\.) or (|) isn't followed 1 (\.(?!\d)).
actual python code:
import re p = re.compile(ur'((?<!\d)\.|\.(?!\d))') test_str = u"happy1...\nhello, world.\n1.2\nholiday" re.findall(p, test_str) please note: in future, should post have tried , why isn't working. questions seeking debugging ("why isn't code working?") must include desired behavior, specific problem or error , the shortest code necessary reproduce in question itself. questions without a clear problem statement not useful other readers. see: how create minimal, complete, , verifiable example.
Comments
Post a Comment