I have the regular expression re.sub(r"(?<!\s)\}", r' }', string)
. What does the (?<!…)
sequence indicate?
It's a bit more than the <
symbol, in the regular expression you've provided.
What's actually there is a 'Negative lookbehind': (?<! )
which is saying "What's before this is not...". In your case, it's looking for }
, on the condition that what comes before it is not \s
- whitespace (tabs, spaces...)
Its a lookback. See the explanation here: http://www.rexegg.com/regex-disambiguation.html#negative-lookbehind
Quoted from the source:
Negative Lookbehind After the Match:
\d{3}(?<!USD\d{3})
Explanation:\d{3}
matches 100, then the negative lookbehind(?<!USD\d{3})
asserts that at that position in the string, what immediately precedes is not the characters "USD" then three digits.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With