简体   繁体   English

用正则表达式升华文本替换模式

[英]Sublime text replace pattern with regex

Using Sublime Text 3 I am trying to find all instances of a <span> element where the class value is not enclosed in quotes – eg <span class=foo> – and I want to wrap the class value in quotes. 使用Sublime Text 3,我试图找到<span>元素的所有实例,其中类值不包含在引号中-例如<span class=foo> -我想将类值包装在引号中。

The following is not working as expected as a search + replace with the regex option activated: 作为激活+ regex选项的搜索+替换,以下各项无法正常工作:

  • Find what: <span class=[A-Za-z0-9]*> 查找内容: <span class=[A-Za-z0-9]*>
  • Replace with: <span class="$1"> 替换为: <span class="$1">

The result I am getting (which I don't want) is <span class=""> 我得到的结果(我不想要)是<span class="">

Highlighting shows that the search term is correctly matching what I want but the $1 part where I want to insert the previously captured pattern does not work. 高亮显示搜索词正确匹配了我想要的内容,但是我要在其中插入先前捕获的模式的$ 1部分不起作用。 I have also tried \\1 in the replace pattern. 我还尝试了\\1在替换模式中。

What is wrong with my syntax? 我的语法有什么问题?

The answer was supplied as comment. 答案作为评论提供。 The pattern to be captured was not wrapped in brackets. 要捕获的图案未用括号括起来。

Tell it what you want to (capture): <span class=([A-Za-z0-9]*)> 告诉它您想要(捕获)的内容: <span class=([A-Za-z0-9]*)>

  • Alex K. 亚历克斯·K。

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

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