regex - how to change `<` to `<` in a string only inside `code` tag using regexp with javascript? -
i want replace < < in string only inside code tag (here point)
for example, here string:
<pre><code class="lang-html"><style> .mydiv { width: 150px; height: 200px; background: red; border-top-left-radius: 100%; } </style> <div class="mydiv"></div> </code></pre> but don't know how write exact regular expression.
i write down below:
var str = `<pre><code class="lang-html"><style> .mydiv { width: 150px; height: 200px; background: red; border-top-left-radius: 100%; } </style> <div class="mydiv"></div> </code></pre> ` str = str .replace(/<code(.|\n|\t|\f|\r|\v)+?(<)(.|\n|\t|\f|\r|\v)+<\/code>/g, (a) => { return '' }) console.log(str) the regular expression can match string, don't how next.
one more question, (.|\n|\t|\f|\r|\v)+? work, [.\n\t\f\r\v] not work, why?
thanks in advance!
Comments
Post a Comment