\s should not be used in the REPLACEMENT part of s///
use warnings; use strict; my $str = 'a|b|c d e '; $str =~ s/[\s|]/_/g; print "$str\n"; $str = "w\nx\ny\nz"; $str =~ s/\n/ /g; print "$str\n"; __END__ a_b_c_d____e__ w x y z
Here is an explanation of your 1st regex (Tip #9 from the Basic debugging checklist):
The regular expression: (?-imsx:\s|\(|\)) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- \s whitespace (\n, \r, \t, \f, and " ") ---------------------------------------------------------------------- | OR ---------------------------------------------------------------------- \( '(' ---------------------------------------------------------------------- | OR ---------------------------------------------------------------------- \) ')' ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------
In reply to Re: Reg exp questions
by toolic
in thread Reg exp questions
by carolw
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |