Quantcast
Channel: MobileRead Forums
Viewing all articles
Browse latest Browse all 50080

Using regex to fix broken paragraph in Chinese

$
0
0
I have some thought, I need someone familiar with regex and text to see if this is doable.

The logic here is simple: I am not going to be 100% correct, just to get rid of annoying breaks.

Since chinses do not have space to identify words, and no capital to identify beginning of sentence, that leads me to think the other way round: What can be used to identify the ending of a sentence?

That be: punctuations!


So, I will regex search a punctuation and a line break right next to each other, that will be 99% the ending of a paragraph!

And the rest is easy.

So this is what I come up with to find the ending:

([\..。\??\!!>》\))\]】}…::—'"’”\|」』@])\n

and replace it with:

\1@@@\n

and replace:

@@@ to \n


Of course, you need to prepare the text first by removing excess space and empty lines.

So what do you guys think? Is there anything to improve?

Viewing all articles
Browse latest Browse all 50080

Latest Images

Trending Articles



Latest Images