MATCH (p:Person)
WHERE p.name =~’Tom.*’
RETURN p.name
What does 'regular expressions' mean? And I've never seen the .* pattern before, I thought the dot operator is always used to retrieve a property of something?
/
2) Why doesn't this query work?
MATCH (p)-[r]-(m)
WHERE p:Person AND type(r)='WROTE' AND type(m)="Movie"
Return p.name, m.title
is type() only applicable to relationships and not labels?
/
3) When to use CONTAIN vs IN?
MATCH (a:Person)-[r:ACTED_IN]->(m:Movie)
WHERE m.title IN r.roles
RETURN m.title as Movie, a.name as Actor
Vs
MATCH (a:Person)-[r:ACTED_IN]->(m:Movie)
WHERE m.title CONTAINS r.roles
RETURN m.title as Movie, a.name as Actor
1- The characters inside the ' ' are part of the regular expression, not the Cypher language anymore. A regular expression is something that describe a pattern instead of a specific sequence of characters. Ex: 123 is a sequence of 3 numbers. 'sequence of tree numbers' is the pattern describing it. In the regex language you can write it as /d{1,3}
The . symbol in a regular expression means roughly any characters.
The * symbol in a regular expression means repeat the preceding character 0 to infinite times.
So Tom.* means every name who begins by the exact characters Tom whatever the characters after the Tom word.
2 - type function is used to know the type of a relation only, a node () doesn't have a type but a set of labels you can use the labels() function for them.
3- IN check if a element is a part of a list
CONTAINS check if a string contains a substring
IN check if a element is a part of a list
where element can be any kind of primitive data type including a string
In this case, the property roles of the ACTED_IN relationship referred by the r variable is a list of strings, and m.title is a simple string. So m.title IN r.roles means in english :
Is the value of the property m.title ( a string ) a part of the r.roles property's value ( A list )
So is the string an element of this list of string