perl 正则表达式中缺少最后一个字符 [英] missing last character in perl regex

查看:41
本文介绍了perl 正则表达式中缺少最后一个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(日志小狗)(日志需求)

(log doggies) (log needs)

^\(log (.*)[^)]\)\s*\(log (.*)[^)]\)$

除了s"结尾缺少字符外,它的工作原理是:

It works with the exception of missing character at the end "s" as:

小狗需要

推荐答案

看起来你的 .* 应该是 [^)]*,即 *任意数量的不是右括号的字符.给予

It looks like your .* should be [^)]*, i.e. *any number of characters that are not closing parentheses. Giving

^\(log ([^)]*)\)\s*\(log ([^)]*)\)$

或者你可以用

while ( $s =~ /\(log ([^)]*)\)/g ) {
    print $1, "\n";
}

这篇关于perl 正则表达式中缺少最后一个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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