Regular expressions with Cypher
By default, Cypher works on an exact match, which is case sensitive in nature. Many times we will know the pattern we want to match, but not the exact value. In this recipe, we will learn to use regex with a Cypher query.
Getting ready
To work through this recipe, you will need to create the nodes and relationships for which data has been provided with the code files.
How to do it...
We have divided this recipe into the following problem sets:
Getting the details: Let's get all the
Airport
names starting with the letterH
:MATCH (n) WHERE "Airport" in LABELS(n) AND n.name =~ '^H.*' RETURN n
You can also specify a label along with the node, as shown in the following code:
MATCH (n:Airport)
The following screenshot shows the Neo4j console depicting the result of all the airports starting with the letter
H
:Making the regex matching case insensitive: Let's get all the airports with names starting with either
H
orh
:MATCH (n) WHERE "Airport" in LABELS(n) AND n.name =~ ...