Reputation: 49
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;}
}
Upvotes: 2
Views: 202
Reputation: 50764
This issue is
The issue is already fixed in the newer engine and you should stop using the deprecated engine to dig out old bugs.
Upvotes: 1
Reputation: 49
Apparently non-capture groups don't work in google scripts, and they aren't planning to fix it. https://issuetracker.google.com/issues/36753681
I updated to this with success:
var regEx = /^H.*\s([A-Z]).*\s([A-Z])\w*\s([A-Z])\w*(\s-.*)$/;
Upvotes: 2