Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Is there anything that would not be matched by /\w\W/i ?

by pileswasp (Monk)
on May 30, 2001 at 14:04 UTC ( [id://84203]=perlquestion: print w/replies, xml ) Need Help??

pileswasp has asked for the wisdom of the Perl Monks concerning the following question:

  • Comment on Is there anything that would not be matched by /\w\W/i ?

Replies are listed 'Best First'.
Re: Is there anything that would not be matched by /\w\W/i ?
by arhuman (Vicar) on May 30, 2001 at 14:34 UTC
    Assuming you talk about /[\w\W]/i the answer is (AFAIK) everything is matched (I've tested french char with accent, spaces, newlines...) except empty string of course...

    Otherwise /\w\W/i doesn't match a lot of things...
      Yep, that was what I was talking about, but it was very early in the morning when the question came up :o)
Re: Is there anything that would not be matched by /\w\W/i ?
by alfie (Pilgrim) on May 30, 2001 at 14:42 UTC
    There are quite many strings that doesn't match your pattern: Everything that contains only of
    • word characters
    • non-word characters
    • non-word characters followed by word-characters
    • the empty string
    If you meant what arhuman thought (/[\w\W]/i) he has forgot that it wouldn't match the empty string, even then.
Re: Is there anything that would not be matched by /\w\W/i ?
by larryk (Friar) on May 30, 2001 at 20:39 UTC
    yes. \w matches any "word" character = [a-zA-Z_0-9]. \W matches anything else. the /i makes no difference in this example (it does not make the regex /[\w\W][\W\w]/ as I think you may believe).

    The following will not match:

    • empty strings
    • single character strings
    • any 2 character string with a \W char followed by a \w char (e.g. '*f', '£L', '+3' etc.)
    • any string > 2 chars comprised solely of \w or \W chars (e.g. 'abcdef', '%^£$' etc.)
    Can't think of any more! Hope this helps - larryk

    "Argument is futile - you will be ignorralated!"

      Replace your third entry above with:

      • a string of \W chars followed by \w chars (e.g. '*%$abc')
      Just FYI. (:

              - tye (but my friends call me "Tye")
Re: Is there anything that would not be matched by /\w\W/i ?
by mpolo (Chaplain) on May 30, 2001 at 14:35 UTC
    Yes. For instance:
    $_="x"; print "Matched" if /\w\W/i;
    will not print Matched. It's easy to have a string that contains no non-word characters.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://84203]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-26 08:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found