var html = "<p><a href='http://www.cnblogs.com/rubylouvre/'>Ruby Louvre</a>by <em>司徒正美</em></p>";
var text = html.replace(/<(?:.|\s)*?>/g, "");
console.log(text);//VM247:3 Ruby Louvreby 司徒正美
Please explain this regular expression to me. I really can’t understand π-π. . .
Thank you
What you have here is the replacement function, which replaces <xxxx> with empty spaces
You can go to https://regex101.com/ and try it yourself. You can enter expressions on the left side. Enter the matched content of the test below. There is a detailed explanation on the right.
In addition, the
|s
in this regular expression is wasteful. You only need to write/<(?:.)*?>/g
. If there is no need to operate on the capturing group, there is no need for non-capturing group. necessary. It can be simplified to/<.*?>/g