How to match a word that contains symbols?

I have this string This is a test -[[message]]- and I want to match -[[message]]-

This is my trying \w+$

How can I do that?

>Solution :

You can use \S, a negative character class matching any character that is not a whitespace character (such as space, tab, new line, etc.):

\S+

Leave a Reply