Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Regex in script include

JusCuz
Tera Guru

I'm trying to process a regex replace in a script include. The code will work in a background script, but fails in a script include.

regex: function(input) {
gs.info('input= '+input);
var cleaned = input.toString().replace(/[-+()\s]/g, '');
gs.info('A= ');
return cleaned;

 

the first gs.info will run, I never get anything from the second. What am I doing wrong?

1 ACCEPTED SOLUTION

JusCuz
Tera Guru

A co-worker who is a much better developer than I found the issue. Apparently AJAX does not bring over the input as a true javascript string. I did see another post where someone mentioned the same thing, but that post didn't have a good way to correct it. The following line corrects the issue:

var stringInput = new String(input);

The script window complains about using String as a constructor, but it does fix the problem.

View solution in original post

6 REPLIES 6

my script works.

replace yours with mine.

JusCuz
Tera Guru

A co-worker who is a much better developer than I found the issue. Apparently AJAX does not bring over the input as a true javascript string. I did see another post where someone mentioned the same thing, but that post didn't have a good way to correct it. The following line corrects the issue:

var stringInput = new String(input);

The script window complains about using String as a constructor, but it does fix the problem.