2

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;}
  
}
2
  • Apparently non-capture groups don't work in google scripts, and they aren't planning to fix it. issuetracker.google.com/issues/36753681 Commented Sep 29, 2020 at 3:42
  • 1
    I glad you found a solution, however, when I run this (or the sample text in the linked Google tracker issue) I get the expected app script output in the console. Strange. Commented Sep 29, 2020 at 3:56

2 Answers 2

2

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-.*)$/;
Sign up to request clarification or add additional context in comments.

2 Comments

The issue is no more valid. I get expected output with both the issuetracker example and your question example also works without error. search is not null. You must have made a mistake in your function that calls abbrevTraining
Reproduced the issue with rhino.
1

This issue is

  • reproducible in engine and
  • NOT reproducible in engine.

The issue is already fixed in the newer engine and you should stop using the deprecated engine to dig out old bugs.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.