Java在忽略括号之间的任何分隔符的同时拆分字符串 [英] Java splitting a string while ignoring any delimiters between brackets
本文介绍了Java在忽略括号之间的任何分隔符的同时拆分字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找java正则表达式来拆分inputString而忽略括号/多个括号之间的分隔符。
I'm looking for java regex to split the inputString while ignoring delimiters between brackets/multiple brackets.
Java代码:
Pattern p = Pattern.compile("[,regex?]");
String[] desiredOutput =p.split(inputString);
例如:
inputString="1,{2,{3},4},{4,5},6";
desiredOutput with;分隔符:
desiredOutput with ; delimiter:
1;{2,{3},4};{4,5};6
Thnx!
推荐答案
使用正则表达式是不可能的。
That's not possible using regular expressions.
表达式必须匹配带平衡括号的字符串。 (这不是常用语言。)
The expression would have to match strings with balanced brackets. (Which is not a regular language.)
您需要使用其他一些解析技术或通过计算 {$ c $手动执行此操作c>和
}
。
You need to use some other parsing technique or do it manually by counting {
and }
.
这篇关于Java在忽略括号之间的任何分隔符的同时拆分字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文