简单 TextWrangler Grep 替换

发布于 2025-01-01 05:21:18 字数 463 浏览 6 评论 0原文

我试图用 h1 替换包含“标题”类的所有 h2 标签:

<h2 class="title">Things</h2>

我正在 TextWranger 中使用多文件搜索:

<h2 class="title">[^>]*</h2>

我能够找到所有内容,但是当我点击替换时,它会将我的标题替换为grep 废话。

BEFORE: <h2 class="title">Things</h2>
AFTER:    <h1 class="title">[^>]*</h1>

我的问题是搜索不仅替换了我的标签,而且还用 [^>]* 替换了我的内容。我也在阿普塔纳尝试过,也发生了同样的事情。我希望能得到一些见解。

I am trying to replace all h2 tags containing the class "title" with h1:

<h2 class="title">Things</h2>

I'm using the Multi-File search in TextWranger with this:

<h2 class="title">[^>]*</h2>

I'm able to find everything, but when I hit replace, it replaces my titles with the grep crap.

BEFORE: <h2 class="title">Things</h2>
AFTER:    <h1 class="title">[^>]*</h1>

My problem is that the search not only replaces my tags but also replaces my content with [^>]*. I also tried this in Aptana and the same thing happened. I would appreciate some insight.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

骄兵必败 2025-01-08 05:21:18

您似乎正在将

转换为 h1?您必须在“替换”中使用反向引用:

搜索:

([^>]*)

替换:< ;h1 class="title">\1(旁白 - 如果它是 h1,您是否仍想保留 'class="title"'?)

注意搜索中的括号正则表达式,保存其中的内容。

然后使用 \1 将它们拉回到替换文本中(\1 表示第一组括号,\2 表示第二组括号,...)

It looks like you're converting <h2 class="title"> to h1? You have to use a backreference in your "replace":

Search: <h2 class="title">([^>]*)</h2>

Replace: <h1 class="title">\1</h1> (aside- if it's a h1 do you still want to preserve the 'class="title"'?)

Note the brackets in the search regex, which save what's inside them.

Then you use \1 to pull them back out in the replace text (\1 for the first set of brackets, \2 for the second, ... )

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文