Parsing email address in to a separate values

Hello, what is the easiest way to parse email addresses when the structure is [email protected] to receive separate values of “name” and “subdomain”.
Tried CODE NODE and Javascript node, tried MATCH and regex. Both are quite complicated and failed to use it.

Anyone did this recently and succeeded?

Update:
Worked this “Code Node” javascript code, just now solving an issue how to replace it with a value from node before:

var email = '[email protected]';
var found = email.match(/^(.*)@(.*?)\.([^.]+)$/);
var obj = {};
if (found && found.length === 4) {
  obj['ID'] = found[1];
  obj['slogan'] = found[2].split('.')[0];
}

return obj;

Hi @Saravicius

Welcome to the community!

I always use the split function to grab things like this. You can use it in a set node.
name: {{$json.email.split(‘@’)[0]}}
subdomain: {{$json.email.split(‘@’)[1].split(‘.’)[0]}}

I know it is not the best solution, but it can be used for all kinds of things and is easy to understand for others as well.

4 Likes

Thanks! It worked!

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.