如何正则表达式分组 [英] How to regex grouping

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

问题描述

我有一个像这样的字符串[Oid,Part.Decription]

我怎样才能获得

firstpart:Stock

secondpart: Oid,Part.Decription with regex。 ,可以更多

解决方案

尝试:

 ^(?< Stock>。+ )\ [(小于?的Oid> +)[,](小于?部分> +)\(小于?说明与GT; +)\] 

如果逗号可以是各种字符,请在'['和']'之间添加它们。

例如,如果它可以是逗号,分号或冒号:

 ^(?< Stock>。+)\ [(?< Oid>。+)[,;:](?< Part> ; +)\(小于?说明与GT; +)\] 


I have a string like this Stock[Oid,Part.Decription]
How can i get
firstpart:Stock
secondpart: Oid,Part.Decription with regex. "," can be more

解决方案

Try:

^(?<Stock>.+)\[(?<Oid>.+)[,](?<Part>.+)\.(?<Description>.+)\]


If the comma can be a variety of chars, add them between the '[' and ']'.
For example, if it could be comma, semicolon, or colon:

^(?<Stock>.+)\[(?<Oid>.+)[,;:](?<Part>.+)\.(?<Description>.+)\]



这篇关于如何正则表达式分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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