gpt4 book ai didi

java.util.regex.PatternSyntaxException : Unmatched closing ')' : during string. 拆分操作

转载 作者:行者123 更新时间:2023-11-30 06:14:07 28 4
gpt4 key购买 nike

我正在尝试执行类似于以下的拆分:

String str = "({Somestring 1 with a lot of braces and commas}),({Somestring 12with a lot of braces and commas})";
println str.split("}),({");

但我明白了:

java.util.regex.PatternSyntaxException: Unmatched closing ')' near index 0 }),({

很明显,我的字符串被视为正则表达式。

有什么办法可以转义这个字符串吗?

最佳答案

字符(){}是正则表达式中的特殊字符。你必须逃避这些:

println str.split("\\}\\),\\(\\{");

关于java.util.regex.PatternSyntaxException : Unmatched closing ')' : during string. 拆分操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30839697/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com