The first sentence of regular expressions

I get a regular expression (compatible with php / perl) to get the first sentence from some text. I understand that this can be enormous if you cover all cases, but only after what is currently "good enough." Has anyone gotten something off the shelf for this?

+3
source share
7 answers

ok, /^[^.]+/is the simplest

+4
source

In the end, you need a natural parsing of the language, which is extremely difficult to do and possibly impossible for regular expressions (even super-super-PCREs). Consider this sentence:

So much for Mr. Reggex and his proposal.

, , , - , " :" - , lookbehinds, , , , . - .. co. . , . " " , , .

+5

, Python : . , , , , , .

+3

"", ^.* . DOT .

, - : ^[^.!?]*

+1

, -, , /^[^\.]*\.\s/, ([\s\S]+?)\.( |\r|\n).

, , , , .

0
/\A(.+?)[.?!] /s

, . , ?

0

.NET:

/(?<=^\s*)(?!\s)("(\<'.*?'\>|.)*"|.)*?((?<='*"*)|[.?!]+|$)(?=\ \ |\n\n|$)/s

( ) ( " " ", " ) , . . .

:

- , " , ?" : " , ". , .

0

Source: https://habr.com/ru/post/1720127/


All Articles