tel2 has asked for the wisdom of the Perl Monks concerning the following question:
Why does this:
perl -e '$a="<abc|def>";$a =~ s/<(.+?)(\|.+?)>/-$1-/;print $a'
give this output:
-abc-
which looks right to me, but this:
perl -e '$a="<abc|def>";$a =~ s|<(.+?)(\|.+?)>|-$1-|;print $a'
(which is the same thing with '|' regex pattern delimiters), give this output:
-a-
I was wanting to use the regex substitution pattern delimiter '|' instead of '/' because my read data had '/' in the text, so '|' meant I didn't have to escape the '/'s.
Perl version: 5.10.1.
Thanks.
tel2
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex delimiters: '/' vs '|' (escaped vs escaped)
by tye (Sage) on Oct 03, 2014 at 03:11 UTC | |
by tel2 (Pilgrim) on Oct 03, 2014 at 03:54 UTC | |
|
Re: Regex delimiters: '/' vs '|' ( m// or s/// or m{} or s{}{} )
by Anonymous Monk on Oct 03, 2014 at 03:03 UTC | |
by tel2 (Pilgrim) on Oct 03, 2014 at 03:47 UTC |