How to check for | in doing substitution in Perl
I have a string with the following data in it
"email@domain.com | firstname | lastname"
I want to replace | lastname
with a different value. If I use s/
to do a substitution, what do i need to do to the | to get it to recognize. If开发者_开发知识库 I do
$foo =~ s/ lastname/fillertext/;
it works fine. but if I do
$foo =~ s/ | lastname/fillertext/;
it doesn't work. I tried to do - \|/ lastname
, "| lastname"
, '| lastname'
.
|
has a special meaning in a regular expression; if you want to match a literal |
, you just need to escape it:
$foo =~ s/ \| lastname/fillertext/;
精彩评论