cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Assign values to multiple variables directly from apoc.text.replace

neo4joe
Node Clone

When I use apoc.text.replace, I often wish to extract several values at once and immediately assign each to its own variable. I normally set up an assignment per variable like this:

UNWIND ["John Smith - Consultant", 
        "Willy Brown - Teacher", 
        "Jen Mack - Radiologist"] AS person

WITH apoc.text.replace(person, '(\w+)\s(\w+)\s-\s(\w)', '$1,$2,$3') AS extract
WITH split(extract,',')[0] AS first,
     split(extract,',')[1] AS last,
     split(extract,',')[2] AS role
RETURN first, last, role

...and that works fine, but I wish I could make that less verbose. I am open to any solution.
For example it would be great if I could do something like load the results directly into a map of named parameters like this:

UNWIND ["John Smith - Consultant", 
        "Willy Brown - Teacher", 
        "Jen Mack - Radiologist"] AS person

WITH apoc.text.replace(person, '(\w+)\s(\w+)\s-\s(\w)', {first:$1, last:$2, role:$3}) AS p
RETURN p.first, p.last, p.role

I'm open to anything that will make the code more concise.

1 ACCEPTED SOLUTION

conker84
Graph Voyager

@neo4joe hi! I think that is a good issue for a feature request, can you please fill it in there:

View solution in original post

2 REPLIES 2

conker84
Graph Voyager

@neo4joe hi! I think that is a good issue for a feature request, can you please fill it in there:

Okay, thanks conker84. I don't see any other responses. So I'll do a feature request.