in reply to Regular Expression Help matching white space but not replacing it
If you count the start and end of the string as spaces,
s/(?<!\S)\Q$user\E(?!\S)/xxxxx/g
If $user is guaranteed to match /^\w/ and /\w\z/, and you're ok with loosening the requirement for spaces, the above can be simplified to
s/\b\Q$user\E\b/xxxxx/g
Update: Added first line to be clear.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regular Expression Help matching white space but not replacing it
by elanghe (Novice) on Aug 11, 2010 at 21:37 UTC |