我需要匹配所有这些开始标记:
<p>
<a href="foo">
Run Code Online (Sandbox Code Playgroud)
但不是这些:
<br />
<hr class="foo" />
Run Code Online (Sandbox Code Playgroud)
我想出了这个,并希望确保我做对了.我只抓住了a-z.
<([a-z]+) *[^/]*?>
Run Code Online (Sandbox Code Playgroud)
我相信它说:
/,然后我有这个权利吗?更重要的是,你怎么看?
我想要一个Javascript Regex来包装给定的start(<span>)和结束标记(即</span>)中给定的单词列表,但前提是该单词实际上是页面上的"可见文本",而不是在html属性中(例如链接的标题标记或<script></script>块内部.
我已经创建了一个基本设置的JS小提琴:http: //jsfiddle.net/4YCR6/1/
可能重复:
替换字符串中的单词,但忽略HTML
调用Replace时是否可以忽略HTML元素?
示例代码:
$myText.replace(new RegExp( $searchString, 'gi' ),
'<span class="highlight">'+ $searchString + '</span>');
Run Code Online (Sandbox Code Playgroud)
$myText 是一个大的HTML字符串,例如:
var $myText =
"<p>Lorem Ipsum is simply dummy text of the printing and typesetting " +
"industry. Lorem Ipsum has been the industry's standard dummy text " +
"ever since the 1500s, <img src="something">when an unknown printer " +
"took a galley of type and scrambled it to make a type specimen book. " +
"It has survived not only five centuries, " + …Run Code Online (Sandbox Code Playgroud) 我正在尝试构建一个简单的CMS,用户可以在contenteditable div中编写任何内容.当他们保存他们的工作时,我想从他们推出的文本中删除特定字符,即:
案文是:
<ul>
<li>This is the text inserted by <b>user</b> and styled by him - there should be no comma at the end of a <b><i><u>LI element,</u></i></b></li>
</ul>
Run Code Online (Sandbox Code Playgroud)
我知道如何用jquery .text()删除逗号,但它只给了我一个没有HTML标签的纯文本.问题是我不知道在应删除逗号的句子末尾是否有多少HTML标记.
有没有其他方法可以删除此逗号而不触及HTML标记?因此,在保存工作后,文本将保持原样,但在LI元素的末尾没有逗号?
简单的小提琴:jsfiddle