我正在尝试使用String.Split()拆分查询,在这种情况下为HiveQL查询。

我遇到的情况是我想沿;拆分,但当;前面带有\时除外。
我的问题 :

String.Split(";")

是不足够的。
String.Split("[^\\\\];")

(即不是\后跟;)应用于
select table; count table;

会给组"select tabl"" count tabl",所以我丢了;之前的字符。

有什么解决办法吗?

最佳答案

为此,您需要一个negative lookbehind:

String.Split("(?<![\\\\]);");

这是一个demo on ideone

关于Java正则表达式: matching a char except when preceded by another char,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16985567/

10-11 22:35
查看更多