Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find all labels that contain string in neo4j

Tags:

neo4j

cypher

Trying to get all nodes of a certain label type. I have roots of multiple graphs that all have the same suffix in their labels. For example, i have 3 nodes that all have treeroot at the end of their label. So I might have companytreeroot, buildingtreeroot, nd employeetreeroot as 3 valid labels for 3 distinct nodes. How would I get all nodes whose label has that pattern?

I tried:

match (n) where '.*treeroot' in labels(n) return n

and

match (n) where 'treeroot' in labels(n) return n

but both return empty sets...

like image 858
WildBill Avatar asked Oct 16 '25 05:10

WildBill


1 Answers

You can use ANY function for apply reqular expression to labels:

match (n) where ANY(l in labels(n) WHERE l =~ ".*treeroot")
return n
like image 79
stdob-- Avatar answered Oct 19 '25 08:10

stdob--