开发者

How to use regex to extract nested patterns

开发者 https://www.devze.com 2022-12-23 01:16 出处:网络
Hi I\'m struggling with some regex I\'ve got a string like this: a:b||c:{d:e||f:g}||h:i basically name value pairings. 开发者_如何学CI want to be able to parse out the pairings so I get:

Hi I'm struggling with some regex

I've got a string like this:

a:b||c:{d:e||f:g}||h:i

basically name value pairings. 开发者_如何学CI want to be able to parse out the pairings so I get:

a:b
c:{d:e||f:g}
h:i

then I can further parse the pairings contained in { } if required It is the nesting that is making me scratch my head. Any regex experts out there that can give me a hand?

thanks,

Rob


Arbitrarily nested patterns is irregular. So, no, you can't just use regex to parse this.


Is there any limit on the depth of nesting in your strings ? If not your language is not regular and regular expressions are the wrong tool -- as you are discovering already.

0

精彩评论

暂无评论...
验证码 换一张
取 消