用正则表达式Look-Ahead做带逃逸的变量替换

| 2 Comments | No TrackBacks
s/\$NICK(?<!\\\$NICK)/$nick/g; 

将文本中$NICK替换为变量$nick, 当且仅当$前不是\. "hello, $NICK"可以被替换, 而"using \$NICK" 在中的$NICK则不会被替换掉.

No TrackBacks

TrackBack URL: http://mtblog.jianingy.com/mt-tb.cgi/196

2 Comments

s/(?

这样可以少打几个字呵呵

晕,被过滤掉了,再试试:

s/(?<!\\)\$NICK/lc/e;

汗,过滤了小于符号,只好写<了呵呵

Leave a comment

October 2008

Sun Mon Tue Wed Thu Fri Sat
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  

Friends' Links

Recent Comments

  • cnhackTNT: 晕,被过滤掉了,再试试: s/(?<!\\)\$NICK/lc/e; 汗,过滤了小于符号,只好写<了呵呵 read more
  • cnhackTNT: s/(? 这样可以少打几个字呵呵 read more

Archives

Powered by Movable Type 4.21-en