Java正则表达式:匹配一个char,除了前面有另一个char [英] Java regex : matching a char except when preceded by another char
本文介绍了Java正则表达式:匹配一个char,除了前面有另一个char的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用String.Split()来拆分查询,在这种情况下是一个HiveQL查询。
I'm trying to use String.Split() to split a query, in that case a HiveQL query.
我有的情况是我要拆分沿;
除非;
前面有 \
。
我的问题:
The case I have is I want to split along ;
except when that ;
is preceded by a \
.
My problem :
String.Split(";")
是不够的。
String.Split("[^\\\\];")
(即不是<$ <$ p
(i.e not a \
followed by a ;
) applied on
select table; count table;
将为群组提供select tabl
, count tabl
,所以我在;
之前丢失了字符。
will give groups "select tabl"
, " count tabl"
, so I lose the character before the ;
.
有什么解决方案吗?
推荐答案
您需要负面观察:
String.Split("(?<![\\\\]);");
这是一个演示版想法。
这篇关于Java正则表达式:匹配一个char,除了前面有另一个char的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文