Dreamweaver 用正则表达式替换
我在使用正则表达式在 Dreamweaver 中进行简单的查找和替换时遇到问题。
这是我的查找框中的内容:
<div id="title">([^ö]*)</div>
这是我的替换框中的内容
<div id="title">
<div class="center">
$1
<span>hello there</span>
</div>
</div>
如果我对此运行上面的查找和替换:
<div id="title"><h1>Page title</h1></div>
<div class="content">
more content
</div>
我无法得到此结果:
<div id="title">
<div class="center">
<h1>Page title</h1>
<span>hello there</span>
</div>
</div>
<div class="content">
more content
</div>
因为查找框的内容没有定义我只想要<之间的内容div id="标题">第一个< /div >...
有什么想法吗?
I'm having a problem with a simple Find and Replace in Dreamweaver using a regex.
This is what's in my find box:
<div id="title">([^ö]*)</div>
This is what's in my replace box
<div id="title">
<div class="center">
$1
<span>hello there</span>
</div>
</div>
If I run the find and replace above on this:
<div id="title"><h1>Page title</h1></div>
<div class="content">
more content
</div>
I can't get to this result:
<div id="title">
<div class="center">
<h1>Page title</h1>
<span>hello there</span>
</div>
</div>
<div class="content">
more content
</div>
Because the content of de find box does not define that I only want the content between < div id="title" > and the first < /div >...
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
至少可以说,将标记语言与正则表达式匹配是很棘手的。
在您的情况下(假设您正在搜索和替换的
标记不包含任何嵌套
标记),您可以使用用作
您的搜索正则表达式。
[\s\S]
匹配任何字符,包括换行符(更多的是
我想说,比
[^ö]
更明确)。匹配零个或多个
?
让明星变得“懒惰”,意味着
它将匹配尽可能少的字符
可能 - 从而确保
匹配将在下一个
处停止。
Matching markup languages with regexes is tricky to say the least.
In your case (assuming that the
<div>
tags you're searching and replacing won't contain any nested<div>
tags), you could get by with usingas your search regex.
[\s\S]
matches any character,including linebreaks (that's more
explicit than
[^ö]
, I'd say).*
matches zero or more of those
?
makes the star "lazy", meaning that
it will match as few characters as
possible - thereby ensuring that the
match will stop at the next
</div>
.