I\'m having trouble getting this Javascript Regular Expression to work.
What i want is to find a character that starts with @\" has any characters in the middle
Gumbo's regexp is very nice and all, however it fails to detect escaped quotes (e.g. \", \\\", etc.). A regexp that solves this is as follows:
/@(["'])[^]*?[^\\](?:\\\\)*\1|@""|@''/g
An explanation (continuing from Gumbo's explanation):
[^\\] matches the nearest character preccedding the ending quote that is not a backslash (to anchor the back-slash count check).(?:\\\\)* matches only if the number of backslashes is a multiple of 2 (including zero) so that escaped backslashes are not counted.|@"" checks to see if there is an empty double quote because [^\\] requires at least one character present in the string for it to work.|@'' checks to see if there is an empty single quote.