Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^4: About a piece of code

by Marshall (Prior)
on Aug 05, 2009 at 15:47 UTC ( #786149=note: print w/ replies, xml ) Need Help??


in reply to Re^3: About a piece of code
in thread About a piece of code

\s is the single space ' ' character. In your set [ \t\n\r\f] that thing right before the \t is \s.

Oooh I see now... in a character set [\s\t\f\r\n], \s means a single space.
in a regex \s means all of the chars in this set: [\s\t\f\r\n]. Yep, confusing!!
\s has a context dependent meaning. Such as it is.


Comment on Re^4: About a piece of code
Select or Download Code
Re^5: About a piece of code
by jwkrahn (Monsignor) on Aug 05, 2009 at 19:10 UTC

    \s is not a single character in a regular expression, it is the character class [ \t\n\r\f].   See perlre.

    $ perl -le' use Data::Dumper; $Data::Dumper::Useqq = 1; print Dumper grep /\s/, map chr, 0 .. 255; ' $VAR1 = "\t"; $VAR2 = "\n"; $VAR3 = "\f"; $VAR4 = "\r"; $VAR5 = " ";

    In a double quoted string it is just the character "s".

    $ perl -le' use Data::Dumper; $Data::Dumper::Useqq = 1; print Dumper "\s"; ' $VAR1 = "s";
Re^5: About a piece of code
by JadeNB (Chaplain) on Aug 05, 2009 at 21:57 UTC
    I think that, since the common regex wisdom involves replacing a literal space in an /x-modified regex with \s, it's easy to think of \s as a replacement for a literal space—but, if you actually want a literal space (rather than just a single whitespace character) in such a regex, but outside a character class, then what you want is '\ ' (i.e., an escaped space).

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://786149]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (10)
As of 2015-07-07 00:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (86 votes), past polls