Perl Regex-打印匹配的值 [英] Perl Regex - Print the matched value

查看:63
本文介绍了Perl Regex-打印匹配的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

打印匹配值的perl正则表达式是什么?例如,我要从此字符串

What is the perl regex to print the matched value? For eg I want to print 195 from this string

"2011-04-11 00:39:28,736::[main]::INFO (Main.java:73) Test.Main::main() Total Successful Transactions = 195".

我该怎么做?预先感谢

推荐答案

您可以在正则表达式中使用括号来捕获子字符串.捕获的组存储在$ 1,$ 2中,依此类推.示例:

You can use parentheses in regex to capture substrings. The captured groups are stored in $1, $2, and so on. Example:

while (<>) {
    if (/Total Successful Transactions = (\d+)/) {
        print "$1\n";
    }
}

或更短一些:

while (<>) {
    print "$1\n" if /Total Successful Transactions = (\d+)/;
}

这篇关于Perl Regex-打印匹配的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆