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 letter H:
    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 ...

Get Neo4j Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.