我想使用空格和单引号拆分字符串。但是应该忽略两个单引号。
输入:
name eq 'a''b'
输出应该是:
name
eq
a''b
我试过
[^\\s\"(?<!')'(?!')]+|\"[^\"]*\"|(?<!')'(?!')[^(?<!')'(?!')]*(?<!')'(?!')"
但它不起作用。
最佳答案
以下应该适合您的需要:
'(?:[^']|'')+'|[^ ]+
Java 示例:
String input = "foobar foo bar 'foobar' 'foo bar' 'foo''bar'";
Pattern pattern = Pattern.compile("'(?:[^']|'')+'|[^ ]+");
Matcher matcher = pattern.matcher(input);
while (matcher.find()) {
String match = matcher.group();
System.out.println(match);
}
关于Java - 根据空格和单引号拆分字符串但忽略两个单引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25360121/