0

段落を文に分割する正規表現があります。

var sentences = /[^\.!\?]+[\.!\?]+/g;

[\.!\?]+句読点 ( ) の後に空白がある場合にのみ一致させたいと思い\sます。試してみ/[^\.!\?]+[\.!\?]+\s/gましたが、うまくいきませんでした。

これが必要な理由は、現在、途中に句読点のある単語がある場合 ( のように) 、そうでない場合に文の終わりを表すabout.meように分割されているためです。.何か案は?

例えば:

この段落がある場合:

If the problem being solved isn't as apparent or immediately useful as traffic about.me and navigation data: weather. A few apps are trying to harness the crowd to provide accurate?

にのみ分割したい

['If the problem being solved isn't as apparent or immediately useful as traffic about.me and navigation data: weather.', 'A few apps are trying to harness the crowd to provide accurate?']

一方、現在はに分割されています

['If the problem being solved isn't as apparent or immediately useful as traffic about.', 'me and navigation data: weather.', 'A few apps are trying to harness the crowd to provide accurate?'].

4

2 に答える 2

1

先読みを使用します:

var re = /[\.!\?]+(?=\s)/g;

var result = "If the problem being solved isn't as apparent or immediately useful as traffic about.me and navigation data: weather. A few apps are trying to harness the crowd to provide accurate?".split(re);

console.log(result.length);  // => 2
于 2013-06-19T19:50:19.983 に答える