Can I use a regular expression in a field transform map script?

HugoFirst
Kilo Sage

I'm trying to use a regex in a field transfor map script to remove HTML markup from a value being imported.

I'm thinking regular expressions aren't supported in this context, but I don't see an error in the logs and I see NO effect on the value when I use a regex.

Has anyone else had this problem?

Here's my script, complete with my trial and errors:

answer = (function transformEntry(source) {

          var tagged_text = source.u_sanesystemdescription.toString();
            log.info("xform tagged text=" + tagged_text + ", starting");
              var textonly = "abc";                                                                                                                               // this works
//           var textonly = tagged_text.replaceAll("^", "abc");                                       // broke
//           var textonly = tagged_text.replaceAll("^(.)", "abc");                                 // broke
//             var textonly = tagged_text.replaceAll("/<[^>]*>/ig", " ");                   // broke
//             var textonly = tagged_text.repalceAll('<.*?>', " ");                                   // broke
            log.info("xform tagged text=" + tagged_text + " complete. New value=" + textonly );
            return textonly; // return the value to be put into the target field
})(source);

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

Hi Steve,



Have you tried using replace() instead of replaceAll()? Watch the quote too! If you are using slash notation, you don't need quotes.



var textonly = tagged_text.replace(/<[^>]*>/ig, " ");



Give that a try.


View solution in original post

3 REPLIES 3

Chuck Tomasi
Tera Patron

Hi Steve,



Have you tried using replace() instead of replaceAll()? Watch the quote too! If you are using slash notation, you don't need quotes.



var textonly = tagged_text.replace(/<[^>]*>/ig, " ");



Give that a try.


Ding ding ding ding!



As usual, your advice was spot on Chuck!


In fact, it was better advice than I get on StackOverflow ( which didn't work! )



Thank you!


Thanks. Glad it works. I don't beat StackOverflow too often.