If you are trying to define a regex in a helper for a lightning component for example and you try to do something like this simple regex to match a single /:

var myRegex = /\//;


var myRegex = new RegExp(/\//gi);

The parser will let you save, but the generated source js file that will be served to load your lightning component will look like this:

var myRegex = /\


var myRegex = new RegExp(/\

This will make the whole page crash in a lightning community for example with the following exception leftover configs Action failed: aura://ComponentController/ACTION$getComponent

My guess is that this is because all comments are removed from the files served as js source and it is picking up the last // of the regex as the start of comments and so it is removing the rest of the line. By the way if you have a component with this in your community it will not load anymore and it will be impossible then to remove that component, even in the builder.

This was very frustrating to figure out also because of the lack of proper error message and the crashing community. Hoping this might help someone else figure out their problem.

(I have not tested this in LEX)


For my usecase, I was able to find a workaround by doing a regex from a string instead of raw like so : var myWorkingRegex = new RegExp('/'); since you do not need to bound your regexes in a string with a / at the end.

It looks pretty straight-forward, just do not have two consecutive // in a raw regex. Two // in a string looks like it is parsed correctly and not removed as comments.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.