The CreatorCon Call for Content is officially open! Get started here.

Simple regex fails in inbound action

e_wilber
Tera Guru

 

The following works perfectly when used in a background script

    gs.print(email.headers.match(/From:.+</g));
    var regExp = new RegExp(/From:.+</g);
    var name = email.headers.match(regExp);
    gs.print(name);
 
and both produce the exact same output. When I try to run this in the inbound action, it fails and I remember from a while back that regexes are tricky in inbound actions. Any idea what I need to do to get this to work?
 
The inbound action is a scoped app.
2 REPLIES 2

Chaitanya Redd1
Tera Guru

Hi,

 

Can you try the below updated script?

// Ensure the regex is constructed properly
var regExp = new RegExp('From:.+<', 'g');

// Extract the matched content using exec() method
var match = regExp.exec(email.headers);

// Check if there's a match
if (match) {
    // Extract the matched substring
    var name = match[0];

    // Print or process the extracted name
    gs.print(name);
} else {
    gs.print("No match found");
}

 

Tony Chatfield1
Kilo Patron

Hi, what is 'failing'? what exactly is your issue\problem, as it is not clear from your post?
Testing your code in a background script and in a scoped inbound action, I do not see any difference in behavior.

Is your issue reproduceable in multiple different instances\a PDI?

What release\version is your platform running?