Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matching a line without either of two words

Tags:

regex

I was wondering how to match a line without either of two words?

For example, I would like to match a line without neither Chapter nor Part. So neither of these two lines is a match:

("Chapter 2 The Economic Problem 31" "#74")

("Part 2 How Markets Work 51" "#94")

while this is a match

("Scatter Diagrams 21" "#64")

My python-style regex will be like (?<!(Chapter|Part)).*?\n. I know it is not right and will appreciate your help.

like image 238
Tim Avatar asked Dec 27 '22 17:12

Tim


1 Answers

Try this:

^(?!.*(Chapter|Part)).*
like image 76
MRAB Avatar answered Jan 11 '23 09:01

MRAB