How does the js regular match the content in <pre><code>xxx&lt;/code</pre>

"

first


console.log(1);

second


console.log(2);
"

want to extract the contents of pre > code and replace them

these are all strings, not dom

Feb.28,2021

provide an irregular way

if it is jq

var html="
console.log(1);
"; Console.log ($(html). Text ());

if you have to use js

var textEle=document.createElement("div");
textEle.innerHTML="<span></span>";
console.log(textEle.innerText);

var html="
console.log(1);
console.log(2);
"; Html.replace (/
(.*?)<\/code><\/pre>/g, "$1");

if there is a regular match, that's it

let str = `
  

console.log(1);

second

console.log(2);
`; Str.match (/ (? < =
)[\s\S]*?(?=<\/code><\/pre>)/gi);  // 

str.replace(/(?<=
)[\s\S]*?(?=<\/code><\/pre>)/gi, 'asdf');  // 
)

where / (? < = somePattern) / is "zero width positive review assertion" < del > thief Kiel length < / del >, / (? = somePattern) / is "zero width positive prediction advance assertion" < del > thief Kiel length * 2 < / del >, / somePattern/g is a global match, / somePattern/i is case insensitive, / somePattern*?/

Menu