Miguel Sanchez Miguel Sanchez - 4 months ago 21
Vb.net Question

Regex exclude brackets

I have the following regex:

[^a-zA-Z0-9](est)[^a-zA-Z0-9]


Test string:

this is a test [est+where] esterius


it should only highlight the first "est". Sadly the bracket [ and the + symbol is also matched. But I want only my word "est" to be matched if the character before and after is non-alphabetical and not numeric

Answer

You should make use of lookaheads and lookbehinds:

(?<=[^a-zA-Z0-9])(est)(?=[^a-zA-Z0-9])

Which basically match something without including it in the resulting match.