2011-03-03 22 views

回答

6

您可以使用正則表達式:

(\$[a-z]+) 

說明:

(  : Start of group 
    \$  : A literal $. Since $ is a metacharacter we escape it. 
    [a-z]+ : one or more letters that is a word. You can use the modifier i 
      to match uppercase letters aswell. 
)  : End of grouping 
+0

@ yb007'\'轉義任何特殊字符 – Vadim 2011-03-03 04:28:45

+0

$ target_str ='這是$$ abc abc $ abc $ abc abc_ $ abc_ing'; $ target_str =〜s /(\ $ abc)/ replaced/g; print $ target_str; **當前輸出**這是$替換abcreplaced替換abc_replaced_ing **預期輸出**這是$$ abc abc $ abc替換abc_ $ abc_ing – yb007 2011-03-03 09:47:44

+1

嘗試使用'$ target_str =〜s /(?<=)(\ $ abc )(?=)/ replacement/g;' – codaddict 2011-03-03 09:54:02