亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

javascript - js regular replacement problem
高洛峰
高洛峰 2017-07-05 10:55:03
0
2
1047
<!DOCTYPE html>
<html>
<head>
    <title>內容</title>
</head>
<body>
中文
<p>內容<i>內容</i></p>
</body>
</html>

Replace the content in the tag with

<!DOCTYPE html>
<html>
<head>
    <title>{{#內容#}}</title>
</head>
<body>
{{#中文#}}
<p>{{#內容#}}<i>{{#內容#}}</i></p>
</body>
</html>

How to write the regular expression?

高洛峰
高洛峰

擁有18年軟件開發(fā)和IT教學經驗。曾任多家上市公司技術總監(jiān)、架構師、項目經理、高級軟件工程師等職務。 網絡人氣名人講師,...

reply all(2)
Ty80

First, if you have learned the principles of compilation, you will know that regular expressions are not capable of processing nested data structures. In other words, if you want to achieve the requirement of [selecting the first i tag of nested p in body] through regular expression, it is not feasible in principle.

Second, you are dealing with a structured DOM text, so you can use jQuery’s parseHTML method to achieve this. The object obtained after passing jQuery parse can use $ to further select nodes such as p or i. This can solve your text replacement problem simply and effectively.

If you are on the Node server, just replace jQuery with cheerio.

Ty80

If you only want to replace in the current test text you gave, because the situation is relatively simple, you only need to write a regular match like ([u4e00-u9fa5]+) and replace it with {{#$1#}}

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template