Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # regex_lookarounds.py
- import re
- # Found many examples that gave faulty results... so I hereby provide my own with... (?!) ... to prove as an accurate explanation
- z = 'abcxyzXYZABC'
- def x(a):
- print re.findall(a,z)
- x( '(?i)abc(?=xyz)' ) # finds the 1st abc ("abc" which has "ABC" after it)
- x( '(?i)abc(?!xyz)' ) # finds the 2nd abc ("ABC" which does not have "abc" after it)
- x( '(?i)(?<=xyz)abc' ) # finds the 2nd abc ("ABC" which does not have "abc" after it)
- x( '(?i)(?<!xyz)abc' ) # finds the 1st abc ("abc" which has "ABC" after it)
- z = 'abc. xyz X. XYZ .A. A.B.C'
- print re.sub('(?<= [A-z])\. ',' ',z)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement