not logical

A

Andrew Hamm

Anonymous said:
Why doesn't ([^\s]) not produce the same result as (\S)?

Because \s is not special inside [ ] so you are litterally saying not \
and not s

only \n \t \b \cX \NNN and the new-fangled \N{NAME} are meaningful
backslashers inside [ ]
 
T

Tassilo v. Parseval

Also sprach Andrew Hamm:
Anonymous said:
Why doesn't ([^\s]) not produce the same result as (\S)?

Because \s is not special inside [ ] so you are litterally saying not \
and not s

only \n \t \b \cX \NNN and the new-fangled \N{NAME} are meaningful
backslashers inside [ ]

I am afraid that's entirely untrue. From perlre:

[...] You may use "\w", "\W", "\s", "\S", "\d", and "\D"
within character classes, but if you try to use them as endpoints of a
range, that's not a range, the "-" is understood literally.

To the OP: Under most circumstances \S and [^\s] should be equivalent. I
am not quite sure however how negated character classes behave when
unicode or locales are in effect. But then, I don't know much about
unicode anyway.

Tassilo
 
M

Mark Shelor

Anonymous said:
Why doesn't ([^\s]) not produce the same result as (\S)?

TIA


Your question uses a double-negative, and is therefore equivalent to:


Why does ([^\s]) produce the same result as (\S)?


Since (\S) does in fact produce the same result as ([^\s]), the
situation you describe is not "not logical" ;)

Regarding Tassilo's mention of Unicode, the following excerpt from
"perlre" might shed some light:


POSIX traditional Unicode

[:^digit:] \D \P{IsDigit}
[:^space:] \S \P{IsSpace}
[:^word:] \W \P{IsWord}


Locales can indeed affect the behavior of isspace(), but one would hope
that any such variations would apply equally to both [^\s] and \S.

Mark
 
A

Andrew Hamm

Tassilo said:
I am afraid that's entirely untrue. From perlre:

Well that freaking tragic. I looked into the Camel book (3rd ed) and
missed that point. I like my regex's but confess to not using these
specials within character classes.

I stand corrected. Might even use it one day!
 

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

Members online

No members online now.

Forum statistics

Threads
474,163
Messages
2,570,897
Members
47,434
Latest member
TobiasLoan

Latest Threads

Top