2016-10-12 6 views
0

これを使用して、(?sm)^.*?\.$私のテキストからすべての段落を取得します。しかし、テキストの最後に「スペース」がある場合、最後の段落は一致しません。これを修正するために何を使用しなければなりませんか?Regex - テキストをウォークしない段落に分割します。

例:私は私の学校のプロジェクトに取り組んできたので、私は((?:[^\n][\n]?)+)を使用

Copyright laws are changing all over the world. Be sure to check the 
copyright laws for your country before downloading or redistributing 
this or any other Project Gutenberg eBook. 

This header should be the first thing seen when viewing this Project 
Gutenberg file. Please do not remove it. 

Please read the "legal small print", and other information about the 
eBook and Project Gutenberg at the bottom of this file.  

look here regex101 example

+0

'(?sm)^。*?\。\ s * $' ...? – brso05

+0

ヒント: '\。$'とはどういう意味ですか? – VGR

+1

https://regex101.com/r/RLu2bv/1 – brso05

答えて

3

私は、このテキストを使用します。少なくとも1行で区切られたすべての段落をキャプチャします(\n)。

これは単純に機能します。改行ではないものをすべてキャプチャするだけです。

Regex101を確認してください。

2

あなたは正規表現を修正したい場合、あなたはパターンの最後に\s*を追加することができます。

^\t*$ 

(?sm)^.*?\.\s*$ 

しかし、あなたはこのような正規表現とsplitメソッドを使用することができます

working demo

関連する問題