【问题标题】:Emacs query-replace-regexp with htmlEmacs 用 html 查询替换正则表达式
【发布时间】:2012-08-08 22:36:22
【问题描述】:

我在 Emacs 中尝试了 replace-regexp 命令,但我不知道如何构造正确的正则表达式。我的文件如下所示:

<img src="http://s.perros.com/content/perros_com/imagenes/thumbs/1lundehund2.jpg" />
<img src="http://s.perros.com/content/perros_com/imagenes/thumbs/1pleon2.jpg" />

我想替换为:

<img src="" class="class-1lundehund2.jpg" />
<img src="" class="class-1pleon2.jpg" />

我使用这个正则表达式没有成功(替换了 0 次):

M-x replace-regexp
  Replace regexp:  src\=\"http\:\/\/s\.perros\.com\/content\/perros_com\/imagenes\/thumbs\/\([a-zA-Z0-9._-]+\)\"
  Replace regexp with: src\=\"\" class\=\"class-\1\"

但在 re-builder 模式下使用相同的正则表达式(更改 \([a-zA-Z0-9.-]+\) by \\([a-zA-Z0-9.-]+\\)) 所有结果都正确突出显示。我不知道发生了什么,有什么提示吗?

【问题讨论】:

    标签: regex emacs replace


    【解决方案1】:

    我认为你逃避了太多的事情。正则表达式 = src="http://s\.perros\.com/content/perros_com/imagenes/thumbs/\([^"]*\)",替换 = src="" class="class-\1"

    【讨论】:

    • 谢谢!它运行得很好。你一定是对的,我逃避了很多事情,再次感谢。
    猜你喜欢
    • 2010-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-24
    • 1970-01-01
    • 2014-10-01
    相关资源
    最近更新 更多