Robert Achmann
Robert Achmann

Reputation: 2035

Regex match line except those with xxx

Here's my data:

public System.Collections.Generic.List<MyItem> MyItemGroupList() {
        return base.Channel.MyItemGroupList();
}

public System.Threading.Tasks.Task<MyItem> MyItemGroupListAsync(){
        return base.Channel.MyItemGroupListAsync();
}

public OtherItem OtherItemByParam(string param) {
        return base.Channel.OtherItemByParam(param);
}

Here's my regex:

/(?<=return base\.Channel\.)(.*?)(?=\(.*\);)/g
MATCH 1
1.  [102-117]   `MyItemGroupList`
MATCH 2
1.  [242-262]   `MyItemGroupListAsync`
MATCH 3
1.  [370-386]   `OtherItemByParam`

But I don't want to match any function with Async in the name. I just can't get it to work.

I've tried inserting (?!Async) but just can't get it.

Upvotes: 0

Views: 151

Answers (1)

Avinash Raj
Avinash Raj

Reputation: 174696

You need to use negative lookahead assertion.

(?<=\breturn base\.Channel\.)(?![^()]*Async)\w+

(?![^()]*Async) asserts that the string going to be matched won't contain the Async until ( is reached.

DEMO

Upvotes: 1

Related Questions