I'm trying to start a project using Tasker(an app developed for android) It has lots of useful plugins and I have stumbled upon google spreadsheet plugin.
With this plugin i can easily read from a spreadsheet.
But my problem is writing into the spreadsheet. I want to use the spreadsheet as a database for my tasker app.
This means it will write simple values to the Spreadsheet examples
A2 = Nexus5/off:1:8:1
A3 = Nexus6/on:2:3:4  
I am now trying to script a search and replace within google scripts. And im getting stuck.
What i want it to do is if my Nexus5 turns on it will send to the spreadsheet in A1 Nexus5/on:1:8:1.  
The script has to search for Nexus5/ in column A and replace the cell value with the new value. After that it has to delete A1 so new input can be put in. Beneath is the script i got so far it can search for an input I put in A1 and replace it in the list with test. But I can't seem to get it search just for the first part.
function replaceInSheet(sheet, to_replace, replace_with) {
  //get the current data range values as an array
    var values = sheet.getDataRange().getValues();
  //loop over the rows in the array
  for(var row in values){
    //use Array.map to execute a replace call on each of the cells in the row.
    var replaced_values = values[row].map(function(original_value){
      return original_value.toString().replace(to_replace,replace_with);
    });
    //replace the original row values with the replaced values
    values[row] = replaced_values;
  }
  //write the updated values to the sheet
  sheet.getDataRange().setValues(values);
}
function onChange(e){
  var sheet = SpreadsheetApp.getActiveSheet()
  replaceInSheet(sheet,val,'test');
}
 
     
    