加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

这个perl正则表达式的含义是什么?

发布时间:2020-12-16 06:08:37 所属栏目:大数据 来源:网络整理
导读:the regex expression is as below:if ($ftxt =~ m|/([^=]+)="(.+)"|o) { ..... } 这个正则表达式似乎与许多其他正则表达式不同.让我困惑的是“|”,大多数正则表达式使用“/”而不是“|”.而且,group([^ =])也让我感到困惑.我知道[^ =]的意思是“字符串的开
the regex expression is as below:
if ($ftxt =~ m|/([^=]+)="(.+)"|o)
   {
    .....
   }

这个正则表达式似乎与许多其他正则表达式不同.让我困惑的是“|”,大多数正则表达式使用“/”而不是“|”.而且,group([^ =])也让我感到困惑.我知道[^ =]的意思是“字符串的开头”或“=”,但是重复’^’一次或多次是什么意思?,怎么解释这个?

解决方法

您可以使用不同的分隔符而不是/.例如,您可以使用:

m#/([^=]+)="(.+)"#o

要么

m~/([^=]+)="(.+)"~o

使用与/不同的东西的优点是你不必转义斜杠,因为否则,你必须使用:

m//([^=]+)="(.+)"/o
  ^

[要么 [/]]

([^ =])是一个捕获组,在里面,你有[^ =]. [^ =]是一个否定的类,将匹配任何不是a =的字符.

^在字符类的开头表现不同,并且与字符类之外的^不同,这意味着“行首”.

至于最后一部分o,这是一个我到目前为止还没有见过的旗帜,所以一点搜索带我到this post,我引用:

The /o modifier is in the 07001 documentation instead of the 07002 documentation since it is a quote-like modifier rather than a regex modifier. That has always seemed odd to me,but that’s how it is.

Before Perl 5.6,Perl would recompile the regex even if the variable had not changed. You don’t need to do that anymore. You could use /o to compile the regex once despite further changes to the variable,but as the other answers noted,qr// is better for that.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读