I am scrapping info from a webpage into Google Sheets using scripts. The information contains addresses similar to 123 Test St, MKE
I am seeking help with a script that will take 'MKE' at the end, and convert it to 'Milwaukee, WI'
I have looked into regex replace functions but cannot solve this problem.
I have also come across code that assists, but does not complete what I am looking for.
function doTest() {
var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
for ( var i = 0 ; i<sheets.length ; i++) {
var sheet = sheets[i];
sheet.getRange('C:C').setValue('Milwaukee');
}
}
Any further suggestions?
Best Answer
The regular expression that matches "MKE" at the end of a string is
MKE$
where$
anchors the match to the end of the string. It's not necessary to use a script to perform such replacement: theregexreplace
function is available, and it can be applied to arrays. For example:If using a script to do the same, the logic would be