Using regex capture groups in a Cypher query

左心房为你撑大大i 提交于 2019-12-11 03:22:02

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!