This should be easy, but I've managed to stump 2 people so far at work & I've been at it for over 3 hours now, so here goes.
I need to replace a+ with aplus (along with a few other cases) with the Python re module. eg. "I passed my a+ exam." needs to become "I passed my aplus exam."
Just using \ba+ works fine most of the time, but fails in the case of a+b, so I can't use it, it needs to match a+ as a distinct word. I've tried \ba+\b but that fails because I assume the + is a word boundary.
I've also tried \ba+\W which does work, but is greedy and eats up the space (or any other non-alpha char that would be there).
Any suggestions please?
Turn that \W
into an assertion.
\ba\+(?=\W)
or, better,
\ba\+(?!\w)
since the negative assertion allows matching the a+
at end of string too.
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