Simple regex fails in inbound action
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2024 12:56 PM
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
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2024 01:40 PM
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");
}
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2024 02:17 PM
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?