If statement - regex for Array -> contains match?

Describe the problem/error/question

I need to see if a specific domain exist in some email addresses in an array. If it does, it should be true ouput.
It seems like the “If” node only matches on exact word?
If my assumption is right, any good workaround?

Information on your n8n setup

  • n8n version:

As always, thanks for great and quick support on questions! :slight_smile:

  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:


you are not correct. Which in your case is in favour of your request.

Simply solution would be to use “contains” for the email.

E.g. contains “gmail.com” or contains “yahoo.com

Be careful with localized email domains (in the mentioned examples - yahoo.de would work as well.

1 Like

Thanks for the reply.

Can you confirm the same for the array alternative? (my case)

My conclusion in my current test is that it doesn’t match array key value when it should.
(Number 4 below should match)


Hey @DkYSwe,

You might be able to do it in one if node, Do you have an example of the array and the value you want to look for.

… I took so long the community are all over it. Nice work :raised_hands:

1 Like

Hey @Jon :slight_smile:

Let assume its some mail-addresses

0: [email protected]
1: [email protected]
2: [email protected]
3: [email protected]

I would like to have a true for “thatdomain”.

As a bonus,
An easy way to split thisdomain arrays elements into a new array thisdomain and the other ones into array thatdomain that would be great. Easy doable? :slight_smile:

Hey @DkYSwe,

If you want to split it into 2 arrays based on the content you could try the below.

This would then give you an output like the below.

From there depending on the end goal there are a couple of options although you could also take the first email array and split it out into items then use an if or switch node to route the emails to a different part of the workflow.

1 Like

Really worked like a charm, thanks. :slight_smile:

To the original question where the “contains” didn’t mach the domain part of the complete array element, can you reproduce that?

Hey @DkYSwe,

Yup it looks like contains expects an exact match so you would need to get more creative, You could use a Bool and if Value is true then select an expression and input {{ $json.emails.some(e => /@thisdomain.com/g.test(e)) }} which would return true once something matches the pattern. It won’t split out the items though.

1 Like

Thanks for confirmation and workaround and of course - excellent support! :slight_smile:

1 Like

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