There is a text file which has key-value pairs as content. The value can optionaly be quoted.
test="value"
Now I need to get the value of a specific keyof, which I do with this regex:
/test=(")?(.*)(?(1)\1|)/m
This is working: https://regex101.com/r/DBAqOx/1
But in the editor
const regex = new RegExp('^' + key + '=(")?(.*)(?(1)\1|)$', 'm')
I do get two errors for this codeline:
Parsing error: Octal escape sequences are not allowed. Use the syntax '\x01'. eslint
Octal escape sequences are not allowed. Use the syntax '\x01'. ts(1487)
>Solution :
A minor typo, but worth explaining in an answer. Because you are using a string literal with the RegExp() constructor, you would need to double escape the backreference as \\1:
const regex = new RegExp('^' + key + '=(")?(.*)(?(1)\\1|)$', 'm')