in reply to Regular Expression Help matching white space but not replacing it

I'd use:
s/(\s)\Q$user\E(\s)/${1}xxxx${2}/;
Note that this does as you define it: only replace it when surrounded by whitespace. It will not replace the user name if the name starts or ends the line.
  • Comment on Re: Regular Expression Help matching white space but not replacing it
  • Download Code

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:36 UTC
    Thank you JavaFan. I must say that's much simpler than what I had been trying.