2011-05-04 64 views
1

做替代我在它如何檢查|在Perl中

"[email protected] | firstname | lastname" 

我想用不同的值來代替| lastname具有下列數據的字符串。如果我使用s/進行替換,那麼我需要做些什麼?讓它認識。如果我做

$foo =~ s/ lastname/fillertext/; 

它工作正常。但如果我做

$foo =~ s/ | lastname/fillertext/; 

它不起作用。我試圖做 - \|/ lastname,"| lastname"'| lastname'

+0

可能重複http://stackoverflow.com/questions/576435 /怎麼辦,我把手 - 特殊字符 - 在-A-Perl的正則表達式) – daxim 2011-05-04 07:36:31

回答

8

|在正則表達式中有特殊含義;如果你想匹配一個|,你只需要逃避它:

$foo =~ s/ \| lastname/fillertext/; 
的[?如何處理在一個Perl的正則表達式的特殊字符(
相關問題