vba regexp match word in string

I’ve been struggling to find solution to what sounds like a simple problem.

I need to find a word “HYD” (capital letters) in a text string. I need match to be exact.

Find in below examples:

text1 HYD text2


Ignore in below examples:

text1 HYDROtext2

text1 MYHYD text2

The closest I was able to get was following pattern:

objRegEx.Pattern = “[^a-z]HYD[^a-z]”

Problem with that is that it will not find “HYD” if string starts or ends with it.

Source: regex

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.