Regular Expressions 101

Community Patterns

Community Library Entry

-2

Regular Expression
Python

r"
# Keys are pretty much "any text before the '=' symbol" (?P<key>[^=]+) # Match the '=' symbol = (?P<value> # Lazy match .*? # Look-ahead (don't move the "regex cursor", just "peek forward") (?= # Match a '_' that has no other '_' between it and the '=' character, or... _(?=[^_=\n]+=) | # ... or the end of the line $ ) ) # Actually "consume" the '_' character if it exists (or just match the end-of-line) (?:_|$)
"
gmx

Description

Awesome explanation of nested lookbacks

Submitted by OnlineCop - 9 years ago