Rename property Neo4j using regex of current property value

From my research (a lot of Googling), I don't see it is possible, but I should still think about it. I have a large collection of nodes like:

(org:Organization {name: "Organization 1234"})

      

where 1234 can be any non-negative integer.

To update the DB to work with the new API, I want to rename each one of them in the collection so that the result looks something like this:

(org:Organization {name: "Org_1234"})

      

So, I need to mashup Org_ with match [0-9] + regex of the current property.

Truly, I am at a loss where to even begin. All I see in the documentation is that regex can be used as a predicate in a WHERE

( WHERE n.property =~ {regex}

) clause . Is there a way to only use Cypher since I am not using the Java library?

+1


source to share


1 answer


Assuming there is always one space between "Organization" and an integer, you can easily copy it using 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

      



What returns

o.name
Org_1234
Org_5678

      

+5


source







All Articles