Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I need a regex to match first sentence of the string

Tags:

regex

I'm trying to come up with a regex which would match the first sentence of the string. I don't need anything too complex, just a sentence that ends with ". " or "! " or "? " note the space after, so that the sentence "I need this domain.com! " would match. I didn't find anything on regexlib.com either. So far I'm stuck with this:

([^.|?|!]*)[\.\s\?\s\!\s]

It's not really working. If I try to match

"I need this domain.com! Another sentence. And another sentence."

I only get "I need this domain." and I need it to be "I need this domain.com!"

like image 794
Caballero Avatar asked Dec 02 '25 10:12

Caballero


1 Answers

Try this :

^.*?[\.!\?](?:\s|$)
like image 82
manji Avatar answered Dec 05 '25 01:12

manji



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!