Regex matching multiple negative lookahead

我怕爱的太早我们不能终老 提交于 2019-11-30 08:50:53

Lookahead (?=foo), (?!foo) and lookbehind (?<=foo), (?<!foo) do not consume any characters.

You can:

^(?!abc:)(?!defg:)

or

^(?!defg:)(?!abc:)

The order does not make a difference.

Try doing this :

^(?!(?:abc|defg):)

… or could have dropped the alternation from the original expression:

^(?:(?!abc:)(?!defg:))
AJP

^(?!abc:|defg:)\s*\w+

use this regex. this will avoid line start with "abc:" and "defg:" as you want.

This will do the task :

^(?!(defg|abc):).*
^(?:(?!abc:|defg:).)*$

Try this.See demo.

http://regex101.com/r/hQ9xT1/18

Could you please try this:

use strict;
use warnings;
use Cwd;

while(<DATA>)
{
    my $line=$_;
    print $line unless($line=~m/^(abc|defg*)/m);
}

__DATA__
ebc this is testing ebc
dbc this is testing dbc
defg this is testing defg
abc this is testing abc
defg this is testing defg
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!