问题
From my research (lots of Googling), I can not see that this is possible, but it is still worth asking I think. I have a large collection of nodes like:
(org:Organization {name: "Organization 1234"})
where 1234 can be any non-negative integer.
In order to update the DB to work with a new API, I am wanting to rename each of these in the collection so that the result would look something like:
(org:Organization {name: "Org_1234"})
So, I need to mashup Org_ with the [0-9]+ regex match on the current property.
Truly, I am at a loss on where to even start. All I see in the documentation is that regex can be used as a predicate in the WHERE
clause (WHERE n.property =~ {regex}
). Is there a way using just Cypher as I am not using a Java library?
回答1:
Assuming there is always a single space between "Organization" and the integer, you can brute force this pretty easily with just string functions.
CREATE (:Organization {name:'Organization 1234'}),
(:Organization {name:'Organization 5678'})
MATCH (o:Organization)
WITH o, SPLIT(o.name, " ")[1] AS id
SET o.name = "Org_" + id
RETURN o.name
Which returns
o.name
Org_1234
Org_5678
来源:https://stackoverflow.com/questions/24087753/neo4j-rename-property-using-regex-of-current-property-value