2

我正在尝试创建仅在行首不包含特定单词的数学行的正则表达式。就我而言,“恶魔:”。

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

但这也匹配“deamon:”后面的其余行,这是我不想要的。

输入:

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...

匹配:

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...

我只想:

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

你有人知道如何只匹配行开头没有“deamon:”的行吗?

4

1 回答 1

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

多行标志m意味着^匹配每行的开头,而不仅仅是字符串的开头。
(?!deamon:)是一个否定的前瞻,如果一行以deamon:.

于 2013-02-22T11:57:24.220 回答