gpt4 book ai didi

java - 正则表达式将文本文档拆分为句子

转载 作者:行者123 更新时间:2023-11-30 07:15:29 26 4
gpt4 key购买 nike

我有一个很大的文本字符串,我试图将它拆分成基于“. ? !”的句子。但是我的正则表达式无法正常工作,有人可以指导我检测错误吗?

String str = "When my friend said he likes deep dish pizza one day, I immediately set a time to come back to Little Star. Arguably, the best deep dish pizza in SF...though...I don't believe there are many places that do deep dish pizza. That being said...its not the BEST ever, just the best for the area. They use cornmeal in the crust, or on the baking surface, so there's a bit of extra crunch to it. That being said...I'm not sure how much I like the cornmeal texture to my pizza. I kind of want just a GOOD CRUST, you know? No extra stuff to try to make it more crunchy.";
String[] sentences = str.split("/(?<=[.?!])\\S+(?=[a-z])/i");

但它不是拆分句子。有人可以检测到错误吗?

最佳答案

您的正则表达式有误。 Java 不理解像这样的 PCRE 类型正则表达式的正则表达式:

/(?<=[.?!])\\S+(?=[a-z])/i

使用这个:

String[] sentences = str.split("(?i)(?<=[.?!])\\S+(?=[a-z])");

关于java - 正则表达式将文本文档拆分为句子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17654738/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com