标准表达式匹配 [英] regalar expression match

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

问题描述

Regex的新手,我很难搞清楚这个。


我需要一个基于平衡方括号的正则表达式。

例如:

[$ AA [123]],[BB [bb],CC],[a [b [c]]]


我正在尝试编写一个将上述内容分解为3个部分的注册表:

1)[$ AA [123]](或$ AA [123]没问题)

2)[BB [bb],CC]

3)[a [b [c]]]


基本上,任何时候方括号平衡,我希望能够把这个价值拿出来。


我写道:(?< column> \ [ ([^ \ [\]] *(\ [。* \])*)* \])


基本上,找一个[,然后重复拿非和和非]

字符或者找到一个内部的[...]并取出它们之间的所有内容;

直到你点击一个]。这是后来的部分,因为我看起来不行,

弄清楚如何让括号正确平衡。这只是

正则表达式的意思吗?感谢您的帮助。

解决方案

AA [123]],[BB [bb],CC],[a [b [c]]]


我正在尝试编写一个将上述内容分解为3个部分的注册表:

1)


< blockquote> AA [123]](或


AA [123]没问题。

2)[BB [bb],CC]

3)[a [b [c]]]


基本上,任何时候方括号平衡,我都希望能够采摘

。那个价值。


我写道:(?< column> \ [([^ \ [\]] *(\ [。* \]) *)* \])


基本上,寻找一个[,然后重复采取非[...]和非]

字符或者找到一个内部的[...]并取出它们之间的所有内容;

直到你点击一个]。这是后来的部分,因为我看起来不行,

弄清楚如何让括号正确平衡。这只是

正则表达式的意思吗?感谢您的帮助。


New to Regex and I''m having a hard time figuring this one out.

I need a regular expression what will based on balanced square brackets.
For example:
[$AA[123]], [BB[bb],CC], [a[b[c]]]

I''m trying to write a reg ex that will parse the above into 3 pieces:
1) [$AA[123]] (or $AA[123] would be fine)
2) [BB[bb],CC]
3) [a[b[c]]]

Basically, any time the square brackets balance, I want to be able to pluck
out that value.

I wrote: (?<column>\[([^\[\]]*(\[.*\])*)*\])

Basically, look for a [, then repeatly take either a non-"[" and non-"]"
character or find an internal set of [...] and take everything between them;
until you hit a ]. It''s the later part that doesn''t work as I can''t seem to
figure out how to get the brackets to balance properly. Is this just
something regular expression are not meant to do? Thanks for any help.

解决方案

AA[123]], [BB[bb],CC], [a[b[c]]]

I''m trying to write a reg ex that will parse the above into 3 pieces:
1)


AA[123]] (or


AA[123] would be fine)
2) [BB[bb],CC]
3) [a[b[c]]]

Basically, any time the square brackets balance, I want to be able to pluck
out that value.

I wrote: (?<column>\[([^\[\]]*(\[.*\])*)*\])

Basically, look for a [, then repeatly take either a non-"[" and non-"]"
character or find an internal set of [...] and take everything between them;
until you hit a ]. It''s the later part that doesn''t work as I can''t seem to
figure out how to get the brackets to balance properly. Is this just
something regular expression are not meant to do? Thanks for any help.


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

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