在 Cypher 中使用除匹配之外的正则表达式 [英] Using regular expressions beyond matching in Cypher
本文介绍了在 Cypher 中使用除匹配之外的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我进行以下查询
neo4j-sh (?)$ start n=node(*) where n.name =~ 'u(.*)' return n;
==> +-----------------------+
==> | n |
==> +-----------------------+
==> | Node[311]{name:"u1"} |
==> | Node[312]{name:"u2"} |
==> | Node[313]{name:"u3"} |
==> | Node[314]{name:"u4"} |
我想添加一个userId"属性并将其设置为名称键中的数字.我的意思是我想要
I want to add a "userId" property and set it the number in the name key. I mean I want
==> +-----------------------+
==> | n |
==> +-----------------------+
==> | Node[311]{name:"u1", userId:'1'} |
==> | Node[312]{name:"u2", userId:'2'} |
==> | Node[313]{name:"u3"},userId:'3' |
==> | Node[314]{name:"u4"}, userId:'4' |
现在我需要从 n.name 中去除数字.我怎样才能做到这一点?如何从正则表达式中的 (.*) 中获取值?
Now I need to strip the numbers from n.name. How can I do this? How can I get the value from the (.*) in regex?
推荐答案
你不能在 Cypher 中这样做(据我所知)——regex 只是为了匹配.
You can't do that in Cypher (as far as I know)--regex is just for matching.
如果前面总是只有一个字母,可以取子串:
If it's always just a single letter in front of it, you can take the substring:
start n=node(*)
set n.userId = substring(n.name, 1)
这篇关于在 Cypher 中使用除匹配之外的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文