简体   繁体   中英

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.

The following is not working as expected as a search + replace with the regex option activated:

  • Find what: <span class=[A-Za-z0-9]*>
  • Replace with: <span class="$1">

The result I am getting (which I don't want) is <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. I have also tried \\1 in the replace pattern.

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]*)>

  • Alex K.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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