我正在尝试拆分一个字符串,如String s = "do not split this "split this"";
String[] split = s.split("(?<=\s)| (?=") | ((?=[^A-Za-z0-9])|(?<=[^A-Za-z0-9]));
会给我["do", " ", "not", " ", "split", "this", " ", "split this"];
我想保留所有单词,也保留空格,但忽略双引号内的任何内容~
只是猜测:
String s = "do not split this "split this"";
String[] split = s.split( "(?<!".{0,255}) | (?!.*".*)" ); // do, not, split, this, "split this"
如果空白处被引号包围,则不要在空白处拆分
如果左边的255个字符和空白处右边的所有字符都没有引号,则在空白处进行拆分