Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: ^\s not equal \S?

by allolex (Curate)
on Dec 04, 2003 at 09:18 UTC ( #312148=note: print w/replies, xml ) Need Help??


in reply to ^\s not equal \S?

Here's some data to illustrate what is happening. I think davido's explanation really hits the nail on the head and Anonymous Monk's suggestion YAPE::Regex::Explain will help you isolate what is happening with your experimentation. BTW, including an asterisk in some of the character classes is redundant, other times, you might see all your asterisks disappear from your input---not what you intended, I think.

ladoix% cat 312141.pl #!usr/bin/perl use strict; use warnings; my $phrase1 = "This is a test, \"using quotes of 'two different' types +.\""; $phrase1 =~ s/[\S\W]*//g; print "P1: [$phrase1]\n"; my $phrase2 = "This is a test, \"using quotes of 'two different' types +.\""; $phrase2 =~ s/[\S\w]*//g; print "P2: [$phrase2]\n"; my $phrase3 = "This is a test, \"using quotes of 'two different' types +.\""; $phrase3 =~ s/[\s\W]*//g; print "P3: [$phrase3]\n"; my $phrase4 = "This is a test, \"using quotes of 'two different' types +.\""; $phrase4 =~ s/[\s\w]*//g; print "P4: [$phrase4]\n"; my $phrase5 = "This is a test, \"using quotes of 'two different' types +.\""; $phrase5 =~ s/[^\s\w]*//g; print "P5: [$phrase5]\n"; my $phrase6 = "This is a test, \"using quotes of 'two different' types +.\""; $phrase6 =~ s/[^\S\w]*//g; print "P6: [$phrase6]\n"; my $phrase7 = "This is a test, \"using quotes of 'two different' types +.\""; $phrase7 =~ s/[^\s\W]*//g; print "P7: [$phrase7]\n"; my $phrase8 = "This is a test, \"using quotes of 'two different' types +.\""; $phrase8 =~ s/[^\S\W]*//g; print "P8: [$phrase8]\n"; ladoix% perl 312141.pl P1: [] P2: [ ] P3: [Thisisatestusingquotesoftwodifferenttypes] P4: [,"''."] P5: [This is a test using quotes of two different types] P6: [Thisisatest,"usingquotesof'twodifferent'types."] P7: [ , " ' ' ."] P8: [This is a test, "using quotes of 'two different' types."]

--
Allolex

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2020-10-30 02:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (277 votes). Check out past polls.

    Notices?