正则表达式 – 如何找到下一个不平衡支架?
发布时间:2020-12-14 05:49:15 所属栏目:百科 来源:网络整理
导读:下面的正则表达式捕获到最后一个平衡的所有内容}. 现在,正则表达式能够捕获到下一个不平衡的所有东西}?换句话说,我怎样才能从$str而不是…… {three {four}}获得…… {three {four}} five}? my $str = "one two {three {four}} five} six";if ( $str =~ /
下面的正则表达式捕获到最后一个平衡的所有内容}.
现在,正则表达式能够捕获到下一个不平衡的所有东西}?换句话说,我怎样才能从$str而不是…… {three {four}}获得…… {three {four}} five}? my $str = "one two {three {four}} five} six"; if ( $str =~ / ( .*? { (?> [^{}] | (?-1) )+ } ) /sx ) { print "$1n"; } 解决方法
所以你想要匹配
[noncurlies [block noncurlies [...]]] "}" 块在哪里 "{" [noncurlies [block noncurlies [...]]] "}" 作为语法: start : text "}" text : noncurly* ( block noncurly* )* block : "{" text "}" noncurly : /[^{}]/ 作为正则表达式(5.10): / ^ ( ( [^{}]* (?: { (?-1) } [^{}]* )* ) } ) /x 作为正则表达式(5.10): / ^ ( (?&TEXT) } ) (?(DEFINE) (?<TEXT> [^{}]* (?: (?&BLOCK) [^{}]* )* ) (?<BLOCK> { (?&TEXT) } ) ) /x (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |