Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 当大写字母在小写字母字符之后时要拆分的正则表达式_Java_Regex_String - Fatal编程技术网

Java 当大写字母在小写字母字符之后时要拆分的正则表达式

Java 当大写字母在小写字母字符之后时要拆分的正则表达式,java,regex,string,Java,Regex,String,所以我尝试用正则表达式和java中的split函数拆分字符串。 当非大写字母后面有大写字母时,正则表达式应该拆分字符串 hHere // -> should split to ["h", "Here"] 我正试着像这样分开一根线 String str = "1. Test split hHere and not .Here and /Here"; String[] splitString = str.split("(?=\\w+)((?=[^\\s])(?=\\p{Upper}

所以我尝试用正则表达式和java中的split函数拆分字符串。 当非大写字母后面有大写字母时,正则表达式应该拆分字符串

hHere      // -> should split to ["h", "Here"]
我正试着像这样分开一根线

String str = "1. Test split hHere and not .Here and /Here";
String[] splitString = str.split("(?=\\w+)((?=[^\\s])(?=\\p{Upper}))");
/* print splitString */
// -> should split to ["1. Test split h", "Here and not .Here and not /Here"]
for(String s : splitString) {  
    System.out.println(s);
}
我得到的输出

1. 
Test split h
Here and not .
Here and /
Here
输出我想要的

1. Test split h
Here and not .Here and not /Here

我就是想不出正则表达式来做这件事,你可以使用一个更简单的模式:
(?你可以使用一个更简单的模式:
(?根据我最初的评论

代码 选择1 此选项适用于ASCII字符(不适用于Unicode字符)。基本上,它适用于英文文本


(?根据我的原始评论

代码 选择1 此选项适用于ASCII字符(不适用于Unicode字符)。基本上,它适用于英文文本


(?或者诀窍是使用“向后看”和“向前看”。使用
(?Thx两者都做了诀窍,但(?)或者诀窍是使用“向后看”和“向前看”。使用
(?Thx两者都做了诀窍,但(?你能解释一下你的正则表达式吗?Thx看起来像是起了作用。但是瑞典字母åäö呢?这些字母不会包括在内吧?@howoff参见:
(?@howoff如果你在解析瑞典语,那么就使用ctwheels在评论中给你的第二个选项。别忘了把反斜杠加倍。@Andreas我要上打字课,这样我就可以跟上你了。你能解释一下你的正则表达式吗?Thx看起来很管用。但是瑞典语字母åäö怎么办?那些不在我的字典里正确吗?@howoff请参阅:
中的第二个正则表达式(?@howoff如果您正在解析瑞典语,请使用ctwheels在其评论中提供的第二个选项。别忘了将反斜杠加倍。@Andreas我将学习打字课程,以便跟上您的步伐。
(?<=[a-z])(?=[A-Z])
(?<=\p{Ll})(?=\p{Lu})