VS 2013 find and replace document.getElementById ("elementId"). Value with $ ("# elementId) .val ()

I'm trying to replace everything

document.getElementById("elementId").value

      

from

$("#elementId").val()

      

where the item id changes.

What should be the syntax for Find What and Replace With ?

+3


source to share


3 answers


Click Ctrl+ Shift+ Fto enter the Find and Replace dialog. Then go to the "Replace in files" tab and check the "Use regular expressions" checkbox

In the Find What text box:

document\.getElementById\(\"(?<elem>\w+)\"\)\.value



and in the "Replace with" field enter:

$("#${elem}").val()

+3


source


Check the box Use Regular Expressions

and search:

document\.getElementById\(\"(.*)\"\)\.value



And replace this with:

$("#$1").val()

+2


source


In Notepad ++ Input

document.getElementById("elementId1").value
document.getElementById("elementId2").value
document.getElementById("elementId3").value
document.getElementById("elementId4").value
document.getElementById("elementId5").value
document.getElementById("elementId6").value
document.getElementById("elementId7").value
document.getElementById("elementId8").value
document.getElementById("elementId9").value
document.getElementById("elementId10").value
document.getElementById("elementId11").value
document.getElementById("elementId12").value
document.getElementById("elementId13").value
document.getElementById("elementId14").value
document.getElementById("elementId15").value
document.getElementById("elementId16").value
document.getElementById("elementId17").value
document.getElementById("elementId18").value
document.getElementById("elementId19").value
document.getElementById("elementId20").value
document.getElementById("elementId21").value
document.getElementById("elementId22").value

      

In the Find / Replace field

Find what: document\.getElementById\(\"(.+)\"\)\.value
Replace with: $\("#\1"\).val\(\)
Search Mode: Regular Expression

      

Output:

$("#elementId1").val()
$("#elementId2").val()
$("#elementId3").val()
$("#elementId4").val()
$("#elementId5").val()
$("#elementId6").val()
$("#elementId7").val()
$("#elementId8").val()
$("#elementId9").val()
$("#elementId10").val()
$("#elementId11").val()
$("#elementId12").val()
$("#elementId13").val()
$("#elementId14").val()
$("#elementId15").val()
$("#elementId16").val()
$("#elementId17").val()
$("#elementId18").val()
$("#elementId19").val()
$("#elementId20").val()
$("#elementId21").val()
$("#elementId22").val()

      

-1


source







All Articles