RegEx Compliance for Neo4j Numeric Property

I have a pair of nodes sharing a property with a numeric value. I would like to filter this property using an expression in the form of an expression. Is this possible using the Cypher query language?

Example:

A { num: 3 } B { num: 12 } C { num: 532 } D { num: 1423 } 

How can I get all the nodes where the num property contains the number 3 (should return A, C and D). I tried something like n.num =~ '3' , but this leads to an error (" java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.String) ")

Any ideas?

+4
source share
2 answers

In doing so, you are trying to apply RegExp to a property of type Long, which is unacceptable. Defining node properties as strings will work, see http://tinyurl.com/bqoq62q

Otherwise, autostart support is supported, so you can (in future versions of Cypher) do where (node.num+'') =~ '3' to do this even with Long. But not right now.

+2
source

I don't quite understand what cypher is (it doesn't look like a regular expression), but the regular expression you want is like this (assuming you can't have nested curly braces ;, a regular expression is not possible for this).

 ([AZ]\s*\{[^\}]*num:\s*3\D[^\}]*\}) 

This will correspond to a single capital letter followed by an open curly brace, and has a number: 3 in front of any closing curly brace. All this was remembered later thanks to parentheses.

0
source

Source: https://habr.com/ru/post/1433624/


All Articles