在两个标签之间替换HTML [英] Replace HTML between two tags

查看:133
本文介绍了在两个标签之间替换HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做的是替换两个HTML标记之间的内容.

What I want to do is replace what is in between two HTML tags.

我以此为参考,但仍然遇到问题: 参考

I'm using this as a reference but I'm still encountering problems: REFERENCE

这是我尝试过的:

el.getValue().replace(/<form.+<\/form>/, "<div></div>");

我需要动态替换所有表单标签.

I need to replace all my form tags dynamically.

推荐答案

是的.我找到了解决方法.

Yeah. I found a solution.

el.getValue().replace(/<form[\s\S]*?<\/form>/, "<div></div>");

@ [James G]的解释: [\s\S]*?表示[任何字符,包括空格和换行符]任意次,并且?使星号不贪心",因此找到</form>时它将停止(更快).

Explanation by @[James G]: [\s\S]*? means [any character including space and line breaks]any number of times, and the ? makes the asterisk "not greedy," so it will stop (more quickly) when it finds </form>.

查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆