Like in PHP.
preg_prelace("/<([a-z]+)>(.+?)<\/\\1>/is", $text);
This can be used in my \\1
reference to the first parameter, in the JS regular expression is it possible to use this?
Reply content:
Like in PHP.
preg_prelace("/<([a-z]+)>(.+?)<\/\\1>/is", $text);
This can be used in my \\1
reference to the first parameter, in the JS regular expression is it possible to use this?
\n
You can use it, for example, for \1
\2
example:
var regexp = /(['"])[^'"]*\1/;console.log( regexp.test("'1'"), regexp.test('"2"'), regexp.test('"3\'')); /* true true false */
Of course you can.
/<([a-z]+)>(.+?)<\/\1>/.exec("xxx")
PS. Because it's not in a string, so you don't need two backslashes.
Yes, but JS String.replace(reg,newStr)
can directly use the regular literal, so do not wrap in the string inside.
1 2 n The number of substrings in the regular; you can use $ $n to refer to the string content that is matched to
For example, replace the matching tag with an empty string:
var str = 'hello world
';str.replace(/<([a-z]+)>(.+)<\/\1>/i,'<$1>
');//