in reply to Reg exp questions
\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 ----------------------------------------------------------------------
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Reg exp questions
by carolw (Sexton) on Nov 07, 2014 at 19:27 UTC | |
by toolic (Bishop) on Nov 07, 2014 at 19:31 UTC | |
by carolw (Sexton) on Nov 07, 2014 at 19:38 UTC | |
by toolic (Bishop) on Nov 07, 2014 at 19:48 UTC | |
by carolw (Sexton) on Nov 07, 2014 at 20:37 UTC | |
| |
by carolw (Sexton) on Nov 08, 2014 at 19:59 UTC | |
| |
|
Re^2: Reg exp questions
by carolw (Sexton) on Nov 08, 2014 at 19:33 UTC | |
by ww (Archbishop) on Nov 08, 2014 at 19:48 UTC |