我想用正则表达式打破句子

时间:2014-11-18 12:40:33

标签: java regex split

我在字符串

中有以下内容
String checker="The United States is a federal union of 50 states. The original 13 states were the successors of the 13 colonies that rebelled against British rule."

我想将其拆分为子部分,以便

String Values[]=new String[20];
Value[0]="The United States is a federal union of 50 states."
Value[1]="The original 13 states were the successors of the 13 colonies that rebelled against British rule."

那就是我想基于" ."我该怎么做?记得" ."用于正则表达式中的任何字符,这就是我被卡住的原因

用什么写

values[]=checker.split("regular exprression..........");

2 个答案:

答案 0 :(得分:1)

(?<=\.)

对于java,请尝试(?<=\\.)

试试这个。点击这个。看看演示。

http://regex101.com/r/lZ5mN8/20

使用正面的lookbehind确保分割发生在.之后或在分割点之前有.

答案 1 :(得分:0)

你可以使用分割功能。 \是指定'。'字符

for ( String s : checker.split( "\\." ) )
        System.out.println( s );
相关问题