created | modified | tags | type | status | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
2025-02-19 09:01 |
|
|
|
x(?=y)
matches with x
only if it is followed by y
import re
re.findall(r"\b[a-z]+(?=\d+\b)", "abc69 def ghi4 jk20l xyz")
# ['abc', 'ghi']
x(?!y)
matches with x
only if it is NOT followed by y
import re
re.findall(r"\b[a-z]+(?!\d+\b)", "abc69 def ghi4 jk20l xyz")
# ['ab', 'def', 'gh', 'jk', 'xyz']
(?<=x)y
matches with y
only if it preceded by x
import re
re.findall(r"(?<=[ck])\d+", "abc69 def ghi4 jk20l xyz")
# ['69', '20']
(?<!x)y
matches with y
only if it is NOT preceded by x
import re
re.findall(r"(?<![a-z]{3})\d+", "abc69 def ghi4 jk20l xyz")
# ['9', '20']
- Links to other notes which are directly related go here