Обговорення » Creation Requests

Script to Split Paragraph into sentences

§
Опубліковано: 08.12.2014

Script to Split Paragraph into sentences


I am looking for a javascript script regex that I can use within GreaseMonkey. I have this so far...

input.replace(/\.\s{1,2}([A-Z])/g,'.\n$1')

My goal is to take an article I run across and run the script to place every sentence on a new line. I guess the regex needs to find a period then a space, then a capital letter. Then place a CRLF at the space marker. This is very basic and I know there will be errors, but its a start.

Unless you are aware of a script that segments paragraphs by sentences in real time (on webpage). Hope that makes sense, thanks for any assistance.

The above paragraph will look like this.
----------------------------------------------------------
My goal is to take an article I run across and run the script to place every sentence on a new line.

I guess the regex needs to find a period then a space, then a capital letter.

Then place a CRLF at the space marker.

This is very basic and I know there will be errors, but its a start.
-----------------------------------------------------------

§
Опубліковано: 08.12.2014
Edited: 08.12.2014
> 'This is a sentence. Another one. And another one.'.replace(/\. ([A-Z])/g, '.\n$2');

'This is a sentence.
Another one.
And another one.'

Edit: If you mean a new line in html, then <br> instead of \n.

Опублікувати відповідь

Sign in to post a reply.