I have a simple input tags looking like this
<input type="password" name="repassword" placeholder="Enter password">
I want to use Sublime Text 3 and add a aria-label
with the same code as in placeholder
. The final result I want to be like this
<input type="password" name="repassword" placeholder="Enter password" aria-label="Enter password">
I put this regex inside the Search field <input.*?placeholder="(.*?)"
And this inside the Replace filed <input.*?placeholder=".*?" aria-label="$(1)"
But i end up with this <input.*?placeholder=".*?" aria-label="$(1)">
Update: I have enabled RedEx button in Sublime Text, this is not the problem. As searching is working great.
You have a couple of problems going on here.
The character sequence .*?
doesn't have any special meaning in the replacement text, only in the original search. Thus including that in the replacement text just puts those exact characters back. If your intention is to put back the same text that was there originally, you need to capture
it like you're doing with the placeholder
text as well.
Secondly, the syntax for inserting captured text back is \1
or $1
; $(1)
is also not special and just injects those characters directly.
To extend your original example, you want to capture the first .*?
as well as the second one, and change the replacement text to suit:
Find: <input(.*?)placeholder="(.*?)"
Replace: <input$1placeholder="$2" aria-label="$2"
Note that the first capture is numbered 1
, the second 2
and so on.