Reading this discussion, I didn’t understand what this means:
$1X$2
Simply X?
And about this other code:
str = str.replace(/(<script.*?>)(.*)(?=<\/script>)/gi, function(x,y,z)
{return y+z.replace(/a/gi,'Z')})
Here is what I didn’t understand:
?=- how does
function(x,y,z)works? i.e. from where it takex,yandz?
I’ll be very grateful if someone could explain in a clear way this code.
The $1 and $2 are referencing the captured sub-expressions (which are delimited by parentheses
()) from the regular expression in the previous argument to.replace().The ?= is a positive lookahead. http://www.regular-expressions.info/lookaround.html
The
function(x, y, z)is an anonymous function expression that does a similar thing to referencing $1 and $2, but it stores them in variables instead.