Sublime Forum

How to find all inputs(html) and copy their names to their values?

#1

Hi everybody!
How to find all inputs(html) and copy their names to their values?
Example html:

 <input name="name" type="text" value="{111}" onchange="Change(this)" title="Some title 1" />
 <input name="phone" type="text" value="{111}" onchange="Change(this)" title="Some title 2" />
 <input name="zip" type="text" value="{111}" onchange="Change(this)" onkeypress="CheckInput(this)" title="Some title 3" />
etc..

I need something like this:

 <input name="name" type="text" value="{name}" onchange="Change(this)" title="Some title 1" />
 <input name="phone" type="text" value="{phone}" onchange="Change(this)" title="Some title 2" />
 <input name="zip" type="text" value="{zip}" onchange="Change(this)" onkeypress="CheckInput(this)" title="Some title 3" />
0 Likes

#2
  1. Find menu -> Replace...
  2. in Find What enter: (<input name="([^"]*)" type="text" value=")([^"]*)(")
  3. in Replace With enter: $1{{$2}}$4
  4. ensure the Regular expression toggle button is enabled.
  5. press Replace All
0 Likes

#3

Thanks!
But it doesn’t work if my inputs have a different type and a different sequence of attributes… :pensive:

Example:

<input name="name" type="text" value="{111}" onchange="Change(this)" title="Some title 1" />
<input name="phone" type="email" onchange="Change(this)" value="{111}" title="Some title 2" />
<input name="zip" value="{111}" type="phone" onchange="Change(this)" onkeypress="CheckInput(this)" title="Some title 3" />

I need to replace only the value of input…

0 Likes

#4

then you can use this regex in the Find What instead: (<input [^>]*name="([^"]*)" [^>]*value=")([^"]*)("), assuming that the name attribute always comes before the value attribute.

3 Likes

#5

thanks again)

0 Likes