![](https://csdnimg.cn/release/download_crawler_static/10471770/bg14.jpg)
Other options are numeric comparisons, matching regular expressions and checking the existence of
values within a list.
The WHERE clause below includes a regular expression match, a greater than comparison and a test to
see if a value exists in a list.
MATCH (p:Person)-[r:ACTED_IN]->(m:Movie)
WHERE p.name =~ "K.+" OR m.released > 2000 OR "Neo" IN r.roles
RETURN p,r,m
+---------------------------------------------------------------------------------------------------------
----------+
| p | r | m
|
+---------------------------------------------------------------------------------------------------------
----------+
| Node[5]{name:"Tom Hanks",born:1956} | :ACTED_IN[1]{roles:["Zachry"]} | Node[1]{title:"Cloud
Atlas",released:2012} |
+---------------------------------------------------------------------------------------------------------
----------+
1 row
One aspect that might be a little surprising is that you can even use patterns as predicates. Where
MATCH expands the number and shape of patterns matched, a pattern predicate restricts the current
result set. It only allows the paths to pass that satisfy the additional patterns as well (or NOT).
MATCH (p:Person)-[:ACTED_IN]->(m)
WHERE NOT (p)-[:DIRECTED]->()
RETURN p,m
+-----------------------------------------------------------------------------------+
| p | m |
+-----------------------------------------------------------------------------------+
| Node[5]{name:"Tom Hanks",born:1956} | Node[1]{title:"Cloud Atlas",released:2012} |
| Node[5]{name:"Tom Hanks",born:1956} | Node[2]{title:"Forrest Gump",released:1994} |
+-----------------------------------------------------------------------------------+
2 rows
Here we find actors, because they sport an ACTED_IN relationship but then skip those that ever
DIRECTED any movie.
There are also more advanced ways of filtering like list-predicates which we will look at later on.
4.3.2. Returning results
So far we’ve returned only nodes, relationships, or paths directly via their variables. But the RETURN
clause can actually return any number of expressions. But what are actually expressions in Cypher?
The simplest expressions are literal values like numbers, strings and arrays as [1,2,3], and maps like
{name:"Tom Hanks", born:1964, movies:["Forrest Gump", …], count:13}. You can access individual
properties of any node, relationship, or map with a dot-syntax like n.name. Individual elements or
slices of arrays can be retrieved with subscripts like names[0] or movies[1..-1]. Each function
evaluation like length(array), toInt("12"), substring("2014-07-01",0,4), or
coalesce(p.nickname,"n/a") is also an expression.
Predicates that you’d use in WHERE count as boolean expressions.
Of course simpler expressions can be composed and concatenated to form more complex
expressions.
18