问题
In the cypher documentation it says you can use regexes to match particular -previously known- patterns in a string attribute.
Is it possible to use capture groups as well?
Take an example:
My node attributes are serialised JSON that look like:
n.json = '{"name": "John", "gender": "m"}'
n.json = '{"name": "Jane", "gender": "f"}'
I want to know relationships between people of different gender:
MATCH r=(n)--(m)
WHERE NOT (n.json =~ '.*gender": "(\c)".*')[1] = (m.json =~ '.*gender": "(\c)".*')[1]
RETURN r
or something like that.
回答1:
Here is a related question. The short answer is that backreferences aren't supported in cypher; regular expressions are just for matching.
In general, when I run into problems like what you're facing, I try to deal with them prior to the import step. I.e. you might start with data, massage it into CSV, and then load the CSV into a graph. During the manipulation of the CSV, I'd do the pattern matching with some other tool (sed/awk/perl/python/whatever) and then modify the data before it gets loaded into the graph to do this sort of thing.
来源:https://stackoverflow.com/questions/25306243/using-regex-capture-groups-in-a-cypher-query