2

大きなテキスト文字列があり、「. ? !」に基づいて文に分割しようとしています。しかし、私の正規表現はどういうわけか機能していません。誰かがエラーを検出するように案内してくれますか?

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");

しかし、それは文を分割していません。誰かがエラーを検出できますか?

4

2 に答える 2

2

正規表現が間違っています。Java は、次の PCRE タイプの正規表現のような正規表現を認識しません。

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

これを使って:

String[] sentences = str.split("(?i)(?<=[.?!])\\S+(?=[a-z])");
于 2013-07-15T12:57:32.890 に答える
2

ここにちょっとしたヒントがあります:

スラッシュは正規表現とは何の関係もありません

スラッシュは、*いくつかの+言語のアプリケーション言語アーティファクトです。Java はその 1 つではありません。

スラッシュを削除し、末尾の「/i」を「(?i)」に置き換えてみてください。

String[] sentences = str.split("(?i)(?<=[.?!])\\S+(?=[a-z])");
于 2013-07-15T12:58:41.143 に答える