please explain to me

R

robertchen117

please explain this to me:

s/\s+(!\W+)/$1 /;


s is replace, expecially (!\W+)
 
A

Alex

please explain this to me:

s/\s+(!\W+)/$1 /;


s is replace, expecially (!\W+)

perldoc perlre
It's an exclamation mark. AFAIK it doesn't have any special meanin, at
least in this context.

So the regexp replaces one or more whitespace characters followed by one
or more non-alphabetic characters beginning with (and including) an
exclamation mark.

For illustration, try using putting parenthesis around the captured
variable like so (dropping the last space):

perl -ane 's/\s+(!\W+)/($1)/;print'
input:
!"#&%asf
!/(%df
!"#¡è%asdf
#¡è%&asdf
output:
(!"#¡è%)asf
(!/(%)df
!"#¡è%asdf
#¡è%&asdf

Note the lack of a space on the third line, and the lack of an
exclamation mark on the fourth line. I guess the ! in the regexp might
have confused you into thinking it to be the NOT-operator?

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top