我试过这个:
+|(?!("[^"]*"))
但它没有用。我还能做些什么来让它工作?顺便说一句,我使用 Java 的 string.split()。
试试这个:
[ ]+(?=([^"]*"[^"]*")*[^"]*$)
仅当这些空格后跟零或偶数个引号(一直到字符串的末尾!
以下演示:
public class Main {
public static void main(String[] args) {
String text = "a "b c d" e "f g" h";
System.out.println("text = " + text + "n");
for(String t : text.split("[ ]+(?=([^"]*"[^"]*")*[^"]*$)")) {
System.out.println(t);
}
}
}
生成以下输出:
text = a "b c d" e "f g" h一个"B C D"e"F g"h
这是你要找的吗?
input.split("(?<!") (?!")")
这行得通吗?
var str="Hi there"
var splitOutput=str.split(" ");
//splitOutput[0]=Hi
//splitOutput[1]=there
对不起,我误解了你的问题从巴特的解释中添加这个s(?=([^"]*"[^"]*")*[^"]*$)
或[ ]+(?=([^"]*"[^"]*")*[^"]*$)