I am trying to create a regex to be able to update calendar event titles that have different training names by turning them into their abbreviations. The regex I created seems to work fine in RegExr and fiddle, but not in google scripts. Can anyone help me figure out why?
Fiddle: https://jsfiddle.net/bpmsa6yr/1/#&togetherjs=vLRcJvkxx9
Google Script (search is null for "Hunt: Marketing Hub Fundamentals - Location Place")
function abbrevTraining(title){
console.log(title);
var regEx = /(?:H[^\s]*)\s([A-Z]).*([A-Z])\w*\s([A-Z])\w*(\s-.*)$/;
try {var search = title.match(regEx);
console.log("regex search: "+search);
var shift = search.shift();
var newTitle = search.join('');
console.log(title+" new: "+newTitle)
return newTitle;
}
catch(e){return title;}
}