匹配 Perl 正则表达式中的平衡括号 [英] Matching balanced parenthesis in Perl regex

查看:46
本文介绍了匹配 Perl 正则表达式中的平衡括号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个需要拆分并存储在数组中的表达式:

I have an expression which I need to split and store in an array:

aaa="bbb{ccc}ddd" { aa="bb,cc" { a="b", c="d" } }, aaa="bbb{}" { aa="b}b" }, aaa="bbb,ccc"

一旦拆分并存储在数组中,它应该看起来像这样:

It should look like this once split and stored in the array:

aaa="bbb{ccc}ddd" { aa="bb,cc" { a="b", c="d" } }
aaa="bbb{}" { aa="b}b" }
aaa="bbb,ccc"

我使用 Perl 5.8 版,有人能解决这个问题吗?

I use Perl version 5.8 and could someone resolve this?

推荐答案

使用 perl 模块Regexp::Common".它有一个很好的平衡括号正则表达式,效果很好.

Use the perl module "Regexp::Common". It has a nice balanced parenthesis Regex that works well.

# ASN.1
use Regexp::Common;
$bp = $RE{balanced}{-parens=>'{}'};
@genes = $l =~ /($bp)/g;

这篇关于匹配 Perl 正则表达式中的平衡括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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