Pattern eqPattern = Pattern.compile("(.*?)([a-z0-9\\_\\.]*) eq \"(((\\\\\")|[^\"])*)\"([\\s]*.*)",Pattern.CASE_INSENSITIVE);
这是我的正则表达式。 当我尝试匹配长字符串时,出现堆栈溢出。 模式将匹配类似 column1 eq“ abc”和column ne“ abc”; (\\\“)| [^ \”]):在“”内部跳过“”。 我想问一下如何重写它以防止堆栈溢出。
Pattern eqPattern = Pattern.compile("(.*?)([a-z0-9\\_\\.]*) eq \"(((\\\\\")|[^\"])*)\"([\\s]*.*)",Pattern.CASE_INSENSITIVE);
这是我的正则表达式。 当我尝试匹配长字符串时,出现堆栈溢出。 模式将匹配类似 column1 eq“ abc”和column ne“ abc”; (\\\“)| [^ \”]):在“”内部跳过“”。 我想问一下如何重写它以防止堆栈溢出。
最好的方法是从正则表达式中删除替代项。
可以这样完成,它使用展开循环:
"(.*?)([\\w.]*) eq \"([^\"\\\\]*(?:\\\\[\\S\\s][^\"\\\\]*)*)\"(\\s*.*)"
原始和扩展
( .*? ) # (1)
( [\w.]* ) # (2)
[ ] eq [ ]
"
( # (3 start)
[^"\\]*
(?:
\\ [\S\s]
[^"\\]*
)*
) # (3 end)
"
( \s* .* ) # (4)