Regex expression

Hi all,
I need a RegEx search expression to lookup words from a list. The words should not start or end with any punctuation characters
e.g. ALL is ok, *ALL is not ok, TEST- is not ok, TEST is ok, …

What I have so far is “\b(ALL|TEST)\b” or (\W|^)(ALL|TEST)(\W|$), that’s working with the words, but punctuation is not
excluded.

Any Help?

Thank’s Peter

Peter can you post your method/function that you also have so far?

Thanks!

It’s hard to say without seeming the actual list. Are you looking for particular words, or any words that meet your criteria?

I’m assuming the latter, so this should work. If I could see the actual text that you’re matching against, it would be better.

\\b(?<![[:punct:]])\\w+\\b(?![[:punct:]])

This looks for a word boundary (\b), then uses a negative lookbehind to make sure the previous character is not a punctuation mark. It then looks for a stream of word characters (\w+) and another word boundary. Finally, it uses a negative lookahead to make sure the next character is not a punctuation mark.

[quote=87847:@Kem Tekinay]It’s hard to say without seeing the actual list. Are you looking for particular words, or any words that meet your criteria?

I’m assuming the latter, so this should work. If I could see the actual text that you’re matching against, it would be better.

\\b(?<![[:punct:]])\\w+\\b(?![[:punct:]])

This looks for a word boundary (\b), then uses a negative lookbehind to make sure the previous character is not a punctuation mark. It then looks for a stream of word characters (\w+) and another word boundary. Finally, it uses a negative lookahead to make sure the next character is not a punctuation mark.[/quote]

That was an unfortunate inability to edit my post. And now I can’t delete the bogus duplicate either.

Kem, thank you, that’s working!

“\b(?<![[:punct:]])(ALL|FOR|TEST|…)\b(?![[:punct:]])”