简体   繁体   English

如何在崇高文本2中进行正则表达式搜索和替换?

[英]How do I do a regex search and replace in sublime text 2?

I want to remove inline style from an html document in ST2. 我想从ST2中的html文档中删除内联样式。

I imagine my regex will be something like this style=\\"*\\" 我想我的正则表达式将是这样的样式= \\“* \\”

If that's wrong, it doesn't matter. 如果这是错的,那没关系。 I'm sure I'll figure out the expression I'll need. 我相信我会弄明白我需要的表达方式。

What I haven't been able to figure out, is how to actually use a regex to find or to find and replace text in ST2. 我无法弄清楚的是,如何实际使用正则表达式来查找或替换ST2中的文本。 The docs say that it can be done. 文档说它可以做到。 But I can't find the documentation for how to do it. 但我找不到如何做的文档。

Simply open the Search+Replace function (via Ctrl-H or the menu bar) and check the first box on the left of it (the one with an '*' on it, or you can press Alt+R) 只需打开Search + Replace功能(通过Ctrl-H或菜单栏)并检查左侧的第一个框(其上带有'*',或者您可以按Alt + R)

Then the search field will be used as a Regex, and you can use the found patterns using the usual $1, $2, $3 vars in the replace box 然后搜索字段将用作正则表达式,您可以使用替换框中通常的$ 1,$ 2,$ 3 vars使用找到的模式

More info here 更多信息在这里

我有类似的任务要执行,我使用的正则表达式是Nas62建议的方式

style=\"(.*?)\"

Find What : style=".*" 找到什么:style =“。*”

Replace With : leave it as blank 替换为:将其留空

Click Replace All button. 单击全部替换按钮。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM