If given (TEXT)testest (GOPHER)mytest (TAG)(not_this)
,
I want to grep only the first occurrence of characters inside parentheses.
The regex results need to be TEXT
, GOPHER
, TAG
, but NOT not_this
because this is not the first occurrence in that word phrase. And the grepped text should be only letters not numbers.
regexp.MustCompile(`(?i)\([a-z0-9_-])+\]`)
// is not working
How do I write the regular expression to grep this? Thank you in advance!
I think the regex you are looking for is:
(?:^|\W)\(([\w-]+)\)
Meaning:
(?:^|\W) /* find but discard the sequence-start or a non-word character */
\(CONTENTS\) /* Contained in () */
(CONTENTS) /* Selection Group */
[\w-]+ /* word character or -, once or more */