Regex: Negative lookahead

Dear Han (I guess),

I want to make sure all my CA symbols are paired up not dangling (for example the °) - and there could be multiple pairs in a given string.

I am trying a negative lookahead.

°(?!°)

However, this returns strings like: [°yeah°]

What am I doing wrong?!

Thanks so much!
Daniel

Dear Daniel,

I’m afraid I’m not a regex expert, but I think the example you show makes sense. The negative lookahead verifies the next character does not match the one in the pattern. In your case ° is not followed by °, which is true for °yeah°.

It’s not so easy to tell what expression could or should be used.

°[^°]+°

would find matching symbols.

°.+°

would find the first and the last and could have any number of occurrences in between.
I don’t immediately see a way to find annotations with an odd number of occurrences of the symbol at hand. And I think it is impossible to determine (by means of regex) which one is the dangling symbol, in case of more than 2 occurrences.

So, I don’t have a good solution.

-Han