How to use variables or repeat through string in regular expressions?
/^(var1)bar(var1)$/.test('foobarfoo') //true
How to use variables or repeat through string in regular expressions?
/^(var1)bar(var1)$/.test('foobarfoo') //true
You want something like this:
So if you wanted to replace "foobarbaz" into "bazbarfoo", you'd do this in sed like this (not sure what language you are using):
s/^(foo)(bar)(baz)$/\3\2\1/
You first capture your desired output with brackets () and then you can use the matches with backreferences like \1 \2 \3.