I want to match any non-word character from the beginning and end position of a string, but if it comes across a non-word character which encloses a string, I want it to stop matching right before it.
I created the following regex pattern:
^\W+(?!(\W+)((?!\1).)+\1)?
I expected it to match like is shown in the following image since it would match any non-word characters from the beginning of the string until it reached the enclosing quotes from the pattern in the negative lookahead:
But the result was this:
What am I doing wrong?

