Helloguys
Helloguys

Reputation: 289

VBA Regex - How to match anything except a specific string?

Sorry if the answer was out there somewhere. I did my research but couldn't find it.

I want to build a regular expression pattern that will match a line in the following format:

  1. Begins with the word "sccp"
  2. Followed by a space
  3. Followed by anything except "ccm group"

I know that ^ in square brackets means "except for any of the characters". How do I exclude a phrase instead of single characters? Obviously, the pattern below didn't do what I wanted:

^sccp [^ccm group]

Thanks!

Upvotes: 1

Views: 926

Answers (1)

Callum Watkins
Callum Watkins

Reputation: 2991

You should be able to use ^sccp (?!ccm group) or ^sccp (?!ccm group).* which uses a negative lookahead to assert that the phrase "ccm group" does not come after the space. Try it here.

If "sccp " should not match (i.e. nothing after the space), then use ^sccp (?!ccm group).+.

Information on the negative lookahead can be found here.

Upvotes: 1

Related Questions