I'm trying to use regular expressions in a cypher WHERE
clause. I would like to match nodes in which a node's property Text
contains a specific word, as a word and not part of it.
MATCH (n:) WHERE n.Text =~ '\bword\b' return n;
This query doesn't return anything although nodes containing the word "word" exist in my graph. Does cypher allow the use of standard regular expressions? Are there limitations in its regular expression implementation?
Administration clauses These comprise clauses used to manage databases, schema and security; further details can found in Database management and Access control. Clause. Description. CREATE | DROP | START | STOP DATABASE. Create, drop, start or stop a database.
To create a relationship between two nodes, we first get the two nodes. Once the nodes are loaded, we simply create a relationship between them. The created relationship is returned by the query.
In Neo4j, since there is no table schema or equivalent to restrict possible properties, non-existence and null are equivalent for node and relationship properties. That is, there really is no such thing as a property with a null value; null indicates that the property doesn't exist at all.
An OPTIONAL MATCH matches patterns against your graph database, just like a MATCH does. The difference is that if no matches are found, OPTIONAL MATCH will use a null for missing parts of the pattern. OPTIONAL MATCH could be considered the Cypher equivalent of the outer join in SQL.
There were 3 problems in your query:
(n:)
should be (n)
, since you are not specifying a label.This query should work:
MATCH (n)
WHERE n.Text =~ '.*\\bword\\b.*'
RETURN n;
See here for documentation related to Regular Expressions in Neo4j
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With