正则表达式-检查其他字符之间的字符 [英] Regular Expressions - Check for char between other chars

查看:78
本文介绍了正则表达式-检查其他字符之间的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本,我想用RegEx分割,但是问题是它的语法是这样的:

I have a text file that I want to split with RegEx, but the problem is that its syntax is something like this:

["string", "string", [("string", int),("string", int)], int, int, string(int, "string")],


我想使用逗号(,)作为分隔符来分割它,但是如您所见,我不想分割许多其他逗号(在示例中,括号()之间的那些逗号).我尝试使用环顾四周,但没有成功.我对正则表达式还很陌生,所以我想问:是否有一种方法可以确定逗号是否在方括号之间(而不是方括号 next ...),并仅使用


I want to split it using the comma (,) as a delimiter, but as you can see, there are a lot of other commas that I don''t want to split (In the example - the ones between () brackets). I tried to use lookarounds, but it didn''t work. I''m fairly new to Regular Expressions, so I wanted to ask: Is there a way to determine if the comma is between brackets (but not next to them...) and split using only the bracket-free commas?

推荐答案

我写了一篇有关您可能感兴趣的字符串拆分的文章.它可能会提供一个起点.

持久性字符串解析器 [
I wrote an article about string splitting you might be interested in. It wouldn''t do exactly what it looks like you need, but it might provide a starting point.

Persistent String Parser[^]


我找到了它.我只是实现了一个解析器,该解析器检查指定字符串中的每个字符是否为逗号.如果逗号不在方括号和内容之间,则我将其作为定界符并与之分隔.
I found it. I just implement a parser which check every char in the specified string for a comma. If the comma is not between brackets and stuff, I accept it as a delimiter and split with it.


这篇关于正则表达式-检查其他字符之间的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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