cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Filter by Regular expression within a list

dptuck
Node Link

I want to modify an existing exact match query that takes a list parameter for filtering

Is there a mechanism to filter based on any of a list of regular expressions:
Something like
WHERE obj.text IN [‘^abc.*’,’.*def$’,’exact’]

1 ACCEPTED SOLUTION

Hello @dptuck and welcome to the Neo4j community

You can use the any() function to match your regular expressions:

WHERE any(regex IN ['^abc.*', '.*def$', 'exact'] WHERE obj.text =~ regex)

Regards,
Cobra

View solution in original post

4 REPLIES 4

D_C
Node Clone

do you have to do it as a list rather than one more complicated regex?
otherwise maybe UNWIND might help you here?

dptuck
Node Link

Thanks for your reply.
Elements come at runtime from different sources (it's a graphql query) so List would be the easiest, compared to a complicated regex, but will look into other options.

Hello @dptuck and welcome to the Neo4j community

You can use the any() function to match your regular expressions:

WHERE any(regex IN ['^abc.*', '.*def$', 'exact'] WHERE obj.text =~ regex)

Regards,
Cobra

Thank you, Cobra.
This works perfectly.