Selective Commas in Title

Hello. I have successfully found a regex that works at regex101 but does not work as expected in Mp3Tag. (Test Data at the end of post.) I want to catch (and remove) any comma that does not meet the conditions below which is why I've used negative lookahead.

Regex:

,\s(?!\w+$)(?!\(\w+)(?!The\s\(.+\))
(?!\w+$) REM Exclude "Something, The"
(?!\(\w+) REM Exclude Some Text, (Other Text)
(?!The\s\(.+\)) REM Exclude "Something, The (More Text)"

Summary of conditions:

NOT Some Text, (Other Text) [e.g. Is This The Way To, (Amarillo)]

NOT Something, The [e.g. Way, The]

NOT Something, The (More Text) [e.g. Way, The (Extended Remix)]

NOT Text, (More text here) (With other text here) [e.g. Devotion, (I Wanna Give You) (12 Inch Mix)]

In the test data, it should catch only commas in the bold text (1 and 2), whilst excluding the others (3,4 & 5):

  1. When The Going Gets Tough, The Tough Get Going
  2. This is it, I'm Done
  3. Some Text, (Other Text)
  4. Something, The
  5. Something, The (Extended Remix)

I'll keep working on it. Thank you

I've managed to simplify and get Mp3 Tag to do as required here with the following:

,(?=\s(?!\(|The))

I believe my previous error may have been the exclusion of an equals sign. Let me know. Thanks

For future readers:

The above regular expression matches a comma only if:

  1. it is followed by a space, and
  2. the next string after the space is neither ( nor The.

More technical:

  1. , -> it matches a literal comma.

  2. (?= ... ) → positive lookahead, this means the comma is only matched if what follows satisfies a condition, but without consuming those characters.

Inside the lookahead: \s(?!\(|The)

  1. \s -> after the comma, there must be a whitespace character (e.g. a space).

  2. (?!\(|The) → negative lookahead -> immediately after that whitespace, it must NOT be:
    ( (an opening parenthesis), or
    The