Avoid repeating yourself. I had several regexes using the 's' modifier, yet still wanted to match optional contiguous non-newline whitespace in many spots. So I used [^\S\n]*
. Except that in several places, I had [\S\n]*
. Oops (it would have been slightly more obvious if I had also taken more advantage of the 'x'modifier). Solution:
my $WS = qr/[^\S\n]*/; ... my $regex = qr/blah,blah,blah,${WS},blah,blah/;or perhaps this would be better (or just as well):
my $WS = qr/(?m).*/;
Re:I don't think your test does what you think...
runrig on 2007-03-23T17:02:04
A quick check of perlre shows that\S
does match all non-whitespace characters, and since your test consists of non-whitespace (including an 'S' which would have matched even if\S
did what you thought it would do), your regex matches. Leave the "S" out of your test string and it will still match...then set the test string to a single "\t" and it won't match:) Re:I don't think your test does what you think...
Yanick on 2007-03-23T17:43:05
*blink*
*open shell*
*typety-type*
*stare*
*blush*
*sigh*
*put on dunce cap*;-)