Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
这是我的字符串:
my $var = "eval(sometext,'|function|65200|url|click|Chargement|margin'.split('|'),0,{}))"
我想得到号码 65200,我尝试了这个my ($key) = $var =~ /eval.*?\|(\d+)\|.*$/正则表达式,但我什么也没得到。
my ($key) = $var =~ /eval.*?\|(\d+)\|.*$/
如果您只需要由十进制数字组成的第一个子字符串,那么它非常简单:
my $var = "eval(sometext,'|function|65200|url|click|Chargement|margin'.split('|'),0,{}))"; my ($num) = $var =~ /(\d+)/; print $num;
输出
65200
更新
要提取由管道字符包围的第一个数字序列,只需使用
my ($num) = $var =~ /\|(\d+)\|/;