\s+(?<request_time>\d+(?:\.\d+)?)\s+ 解释

<pre name="code" class="html"><pre name="code" class="html">看elk 看到一个正则;
\s+(?<request_time>\d+(?:\.\d+)?)\s+

回顾下:
(?:pattern)
 匹 配 pattern 但不获取匹配结果,也就是说这是一个非获取匹配,不进行存储供以后使用。这在使用 “或” 字符 (|) 来组合一个模式的各个部分是很有用。例如, ‘industr(?:y|ies) 就是一个比 ‘industry|industries’ 更简略的表达式。

表示括号只是起分隔作用,不将括号中匹配的内容存入内存中
因为如果不加?:的话,括号内匹配的内容会放入$1,$2...这些变量中

1、命名分组格式为(?<grp name>),反向引用时用\k<grp name>

2、命名分组的匹配的结果存在在变量%+变量中,取命名分组值,$+{grp name}.


[tomcat@wx02 test]$ cat a2.pl 
my $str="456.123a";
if ($str=~/\d+(\.\d+)/){print "\$1 is $1\n"};
[tomcat@wx02 test]$ perl a2.pl 
$1 is .123


[tomcat@wx02 test]$ cat a2.pl 
my $str="456.123a";
if ($str=~/\d+(\.\d+)?/){print "\$1 is $1\n"};
[tomcat@wx02 test]$ perl a2.pl 
$1 is .123

\d+(\.\d+)? 中的?有什么用呢?


x?  匹配 0 次或一次 x 字符串 


[tomcat@wx02 test]$ cat a2.pl 
my $str="456";
if ($str=~/\d+(\.\d+)?/){print "\$1 is $1\n"};
[tomcat@wx02 test]$ perl a2.pl 
$1 is 
[tomca

这里的(\.\d+)? 就是0次或者1次
zjtest7-frontend:/root/test# cat a1.pl 
my $str="456.123a";
if ($str=~/\d+(?:\.\d+)?/){print "\$1 is $1\n"};
zjtest7-frontend:/root/test# perl a1.pl 
$1 is


 
 
 

转载于:https://www.cnblogs.com/zhaoyangjian724/p/6199270.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值