I want to replace the character & with and, but only when & is by itself. I try the following in Python 2.7.3:
import re
re.sub('&', 'and', '& r&b')
I get and randb, but what I want is and r&b.
re.sub('\b&\b', 'and', '& r&b')
Doesn’t work either. Any suggestions? Also, what’s the expression if I just wanted a unique combination of normal characters and special characters, like if I want a&b, but not a&bc?
Couldn’t find the answer in similar questions, so thanks in advance!
Not knowing what “by itself” means. Btw, nobody knows what that means in regex.
Ror your specific example,
search
(^| )&( |$)replace
$1and$2Don’t know Python though.
Edit: In Python