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."]
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|