在Cypher中使用匹配以外的正则表达式 [英] Using regular expressions beyond matching in Cypher

查看:256
本文介绍了在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中做到这一点(据我所知),正则表达式仅用于匹配.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆