Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: ^\s not equal \S?

by Anonymous Monk
on Dec 04, 2003 at 15:04 UTC ( #312208=note: print w/replies, xml ) Need Help??


in reply to ^\s not equal \S?

Welcome to Boolean Algebra!
[^\s\w] = NOT (space OR word) [\S\W] = (NOT space) OR (NOT word) (NOT space) OR (NOT word) = NOT (space AND word)

Replies are listed 'Best First'.
Re: Re: ^\s not equal \S?
by delirium (Chaplain) on Dec 04, 2003 at 15:37 UTC
    Well, I finally did it. I ++'d an anonymous post. Good answer. I was going to say something like:

    [^\s\w] means neither spaces nor words, or, everything but spaces and words, where
    [\S\W] means non-spaces AND non-words, and since a space is a non-word, the meaning is similar to "non-spaces and spaces".

    However, ^\s and \S should be the same, so...

    $phrase =~ s/[^\s*\w*]//g;
    would do the same thing as...
    $phrase =~ s/[\S]|[\W]|[^*]//g;

    Update: No, it wouldn't. :: smacks self in head ::

      Wait a minute.... I just tried your example and it still wipes out the string. It's like a nice big OR isn't it? So isn't s/[\S]|[\W]//g really the same as s/[\S\W]//g?

      Edit: A negative demark for pointing out this out? Bleh, now that isn't exactly fair. Oh well, I still haven't quite worked out what benefits voting would have.
      Anyhow, I've fiddled with the regexes and the response from delirium still doesn't quite fit in with what everything else tells me. Plugging in the two different RegExs in to the script yields completely different results. And given the examples by anon, it would naturally make sense.

      Is it fair to stick a link to my site here?

      Thanks for you patience.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2020-02-21 13:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?










    Results (96 votes). Check out past polls.

    Notices?