Regular expression for line match without specific word

I'm trying to create regular expression that math only lines that not containing specific word at the beginning of the line. In my case "deamon:".

My regex: (?!d)(?!e)(?!a)(?!m)(?!o)(?!n)(?!:).*\n

But this match the rest of line behind "deamon:" too, what I don't want.

Input:

deamon: parsing arguments...
deamon: parsing xml file...
deamon: creating xml file for demo...
deamon: executing demo
parsing arguments...
path to xml: /home/www/www/seg-chapter/tests/users/1/launches/60/demo.xml
parsing xml file...

Match:

parsing arguments...
parsing xml file...
creating xml file for demo...
executing demo
parsing arguments...
path to xml: /home/www/www/seg-chapter/tests/users/1/launches/60/demo.xml
parsing xml file...

I want only:

parsing arguments...
path to xml: /home/www/www/seg-chapter/tests/users/1/launches/60/demo.xml
parsing xml file...

Do you anybody know how to match only lines without "deamon:" at the beginning of the lines?

Answers:

Answer
str.match( /^(?!deamon:).*/mg )

The multiline flag m means ^ matches the start of each line rather than just the start of the string.
(?!deamon:) is a negative look-ahead which prevents a match if a line starts with deamon:.

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.