I came up with: ([^']*['][^']*['][^']*)*
It works in all cases except against the empty string. I thought it would work because the last star matches the previous token zero or more times.
Any ideas?
Also if there’s a much better way of doing this please let me know and explain it in detail.
The solution must be a regex as the place where it will be used is a hook which requires a regex.
It has to match a string without quotes as well, as zero is an even number
your regex should match the completely empty string, but not e.g. a string consisting of a single space, because your regex states that if the string is not completely empty, it needs to contain at least one double quote. This is because of the [‘] tokens inside the regex which are not followed by *.
The proper way to think about the needed regular expression is as follows: you want to match (string without double quotes) followed by (double quote) plus (string without double quotes) followed by (double) quote followed by (string without double quotes), and then repeat starting from the first ‘followed by’ ad infinitum. String without double quotes is [^’]*, so you get (whitespace added for readability):
If you compare this with your regular expression, the first [^’]* has been moved out of the repetition.