我有一个像这样的字符串:
Snt:It was the most widespread day of environmental action in the planet's history
====================
-----------
Snt:Five years ago, I was working for just over minimum wage
====================
-----------
我想用
分割字符串====================
-----------
当然还有从第一个句子中删除 Snt:
。
什么是最好的方法?
我使用了这个正则表达式,但没有用!
String[] content1 =content.split("\\n\\====================\\n\\-----------\\n");
提前致谢。
最佳答案
关于
Pattern p = Pattern.compile("^Snt:(.*)$", Pattern.MULTILINE);
Matcher m = p.matcher(str);
while (m.find()) {
String sentence = m.group(1);
}
与其使用 split
进行破解并进行额外的解析,只是 查找以“Snt”开头的行,然后捕获后面的内容。
关于java - 通过java正则表达式拆分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26183269/