How to match sentences except one that contain a specific word in Regex?

If you have a paragraph or a content and you want to select all sentences that not contain a specific word. Then follow this tutorial, we have come up with best regex for this situation. We have given all in depth knowledge for the regex value given.

Let’s suppose you have a paragraph that contains three sentences and you want to select sentences that not contain your word. Take a below example,

The main dancer of BlackPink is Lisa. The main vocalist of BlackPink is Rose. The main rapper of Blackpink is Jennie. The main visualist of BlackPink is Jisoo.

In this example, if you want to select all the sentences other than sentence contains word “Lisa“. Then the regex for that is given below.


((?<=^)|(?<=.))\s(?![^.](Lisa)).*?(?:.|$)((?<=$)|(?<=.))

Check on Regex101

If you want to exclude multiple sentences with different words then you can use | symbol to add more words. Example given below.


((?<=^)|(?<=.))\s(?![^.](Lisa|Jennie)).*?(?:.|$)((?<=$)|(?<=.))

Check on Regex101


Explanation of the regex.

1st Capturing Group ((?<=^)|(?<=\.))

1st Alternative (?<=^)

Positive Lookbehind (?<=^)Assert that the Regex below matches^ asserts position at start of a line

2nd Alternative (?<=\.)

Positive Lookbehind (?<=\.) Assert that the Regex below matches\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)\s matches any whitespace character (equivalent to [\r\n\t\f\v ])* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)

Negative Lookahead (?![^.]*(Lisa)) Assert that the Regex below does not match

Match a single character not present in the list below [^.]* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy). matches the character . with index 4610 (2E16 or 568) literally (case sensitive)

2nd Capturing Group (Lisa) Lisa matches the characters Lisa literally (case sensitive). matches any character (except for line terminators)*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)

Non-capturing group (?:\.|$)

1st Alternative \.\. matches the character. with index 4610 (2E16 or 568) literally (case sensitive)

2nd Alternative $$ asserts position at the end of a line

3rd Capturing Group ((?<=$)|(?<=\.))

1st Alternative (?<=$)

Positive Lookbehind (?<=$) Assert that the Regex below matches$ asserts position at the end of a line

2nd Alternative (?<=\.)

Positive Lookbehind (?<=\.) Assert that the Regex below matches\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)


If you want the opposite regex of this, that select sentences of specific words then check out below post.

How to Match a Sentence of a Word in Regex?

Leave a Comment