Ian Spitz
Ian Spitz

Reputation: 311

Writing a case-insensitive Cypher query to match the beginning of a string in Neo4j

I'm having trouble while trying to write a Cypher query that returns all the nodes which their name starts with a certain string. I also need this query to be case insensitive.

Cypher has built in functions for both cases, but I don't know how to combine them

Query for matching the beginning of a string:

MATCH (n) WHERE n.Name STARTS WITH 'Pet' RETURN n

Query for case-insensitive strings

MATCH (n) WHERE n.Name =~ '(?i)ANDR.*' RETURN n

Any help will be appreciated.

Upvotes: 1

Views: 2147

Answers (1)

William Lyon
William Lyon

Reputation: 8546

For a case insensitive comparison using the STARTS WITH string comparison operator you can use the toLower() string function to convert each side of the comparison to lower case. For example:

MATCH (n) 
WHERE toLower(n.name) STARTS WITH toLower('Pet') 
RETURN n

Upvotes: 2

Related Questions