perl分组捕获

来源:互联网 发布:外汇交易分析模拟软件 编辑:程序博客网 时间:2024/06/03 18:21

问题如下 :

http://zhidao.baidu.com/question/501928970.html?push=keyword

 

解决如下:

#! /usr/bin/perl -wuse strict;my $string = "abc r=3 def r=3 test r=3 over";print $string , "\n";$string =~ s/(?<=def r=)\d/5/;  #?<=  匹配exp后面的位置print $string , "\n";$string = "abc r=3 def r=3 test r=3 over";  #?=  匹配exp前面的位置$string =~ s/\d(?= def)/5/;print $string , "\n";$string = "abc r=3 def r=3 test r=3 over";  #?!  匹配后面跟的不是exp的位置$string =~ s/\d(?! def)/5/;print $string , "\n";$string = "abc r=3 def r=3 test r=3 over";  #?<!  匹配前面不是exp的位置$string =~ s/\d(?<! def)/5/;print $string , "\n";


 

原创粉丝点击