No" /> No" /> No"/>

Textmate Find regex, Replace wild

173 Views Asked by At

In I can use the syntax (.*) to find both lines in the below use case:

<span class="class1"></span>
<span class="class2"></span>

Now I want to append more code to each of them so my find query is span class="(.*)" and my replace query is span class="(.*)" aria-hidden="true" which i had hoped would result in this:

<span class="class1" aria-hidden="true"></span> 
<span class="class2" aria-hidden="true"></span>

but it actually resulted in this:

<span class="(.*)" aria-hidden="true"></span>
<span class="(.*)" aria-hidden="true"></span>

Using find/replace (not using column selection which would work for this example but not for the actual situation) is it possible to maintain the area matched by regex in the replace action with a representative wild character or something?

2

There are 2 best solutions below

1
Avinash Raj On BEST ANSWER

Change your replace query as,

span class="$1" aria-hidden="true"

$1 would refer the characters which are present inside group index 1.

2
vks On
(<span class="[^"]*")

Try this.Replace with $1 aria-hidden="true".See demo.

http://regex101.com/r/wQ1oW3/22