[SalesForce] Single Quote not getting replaced with Blank in lightning

I have an expression and I am trying to replace all single quote with blank but when I try to save my controller.js it gives error:

Error: 0Adf4000000en6S: org.auraframework.util.json.JsonStreamReader$JsonStreamParseException: Unterminated string [96, 41]: '/g, "");

I am trying this code:

var sqlExpression = 'gattexlead_flag'_1;
var text1 = sqlExpression.replace(/'/g, "");

Best Answer

This is probably a bug with the lexer. You will probably need to escape it:

var text1 = sqlExpression.replace(/\'/g, "");

For now, if you need a regular expression that fails to compile, compile it ahead of time:

var regex = new RegExp("'","g");
var text1 = sqlExpression.replace(regex, "");
Related Topic