我试图根据句号逗号和括号(如 () {} 和 [])将一小段分成句子。如何使用 Java Regex 来做这样的事情
例如,如果我有一个类似的段落
So far I like this car and it is fun to drive. It works very well as a daily driver and has some good kick, although it is still far from a sports car. I have one major issue with this car.Volvo has built heating elements into the windshield (small wires every few millimeters). At night all lights reflect off of these wires and makes the lights blurry. It is a huge safety issue and is extremely annoying. Due to this issue alone, I am not sure if I will keep this car very long. Although it is nice to have a heated steering wheel, skip the Climate Package if you buy this car.
我的分割段落的结果应该是
So far I like this car and it is fun to drive
It works very well as a daily driver and has some good kick
although it is still far from a sports car
I have one major issue with this
Volvo has built heating elements into the windshield
small wires every few millimeters
At night all lights reflect off of these wires and makes the lights blurry
It is a huge safety issue and is extremely annoying
Due to this issue alone
I am not sure if I will keep this car very long
Although it is nice to have a heated steering wheel
skip the Climate Package if you buy this car
最佳答案
你可以尝试这样的事情:
String str = "...";
str = str.replaceAll(" ?[,.()]+ ?", System.getProperty("line.separator"));
如果你想要一个数组,请使用这个:
String[] strArr = str.split(" ?[,.()]+ ?");
for(String strr : strArr)
{
System.out.println(strr);
}
产量:
So far I like this car and it is fun to drive
It works very well as a daily driver and has some good kick
although it is still far from a sports car
I have one major issue with this car
Volvo has built heating elements into the windshield
small wires every few millimeters
At night all lights reflect off of these wires and makes the lights blurry
It is a huge safety issue and is extremely annoying
Due to this issue alone
I am not sure if I will keep this car very long
Although it is nice to have a heated steering wheel
skip the Climate Package if you buy this car
关于java - java中根据特殊字符和括号分割段落,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28668920/