Is there an existing algorithm to find all literal Regular Expression occurrences within a single line of valid JavaScript code?
Given that a literal Regular Expression cannot be multi-line, I need to detect all regular expressions within a single line of code, or more specifically - the beginning and end indexes for each regular expression, if they are present.
function enumRegex(textLine) {
// magic happens here;
}
var testLine = 'var regEx1 = /one/; regEx2 = /two/;';
console.log(enumRegex(testLine));
Expected output: Array of index pairs (start and end index for each RegEx found):
[{13,17},{29,33}]
UPDATE: After playing with this: Is there a regular expression to detect a valid regular expression?, I'm not sure it would even work. So, if someone suggests using a regular expression to detect regular expressions, it would require an example that actually works. I'd rather hope to see an algorithm.