2011-03-03 54 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