0
votes

I have node names in neo4j with names something like "abc124","abcd124","xyz678","zxyz678" etc

In the above node names,abc124 & abcd124 have same numbers(ID/accnt number)-124,so I need to merge these nodes which have same IDs/accnt number. The logic which I'm trying is separate the alphanumeric node names to numbers and then use apoc procedure to merge the nodes

I'm not able to find any function which removes the character part from the node names

I tried toInteger but does not work

RETURN toInteger('42AB')

So my input node names are "abc124","abcd124","xyz678","zxyz678" So my output nodes names I would want is 124,124,678,678....

1
What is the pattern of id/acc number in name? Is it always last 3 digits or something else? - Rajendra Kadam
Only pattern in it is the account number is followed by 'ACCNT:".It is something like "XYZ.........ACCNT: <account no>" - Kaverisonu

1 Answers

0
votes

The APOC function apoc.text.regexGroups may be helpful.

For example:

RETURN TOINTEGER(apoc.text.regexGroups('abc123', '\\d+')[0][0])

returns:

123

[UPDATE]

To merge Foo nodes whose name properties end in the same digits, you can also use apoc.refactor.mergeNodes to help with the node merging (you may also want to specify some of its documented config options, depending on your needs).

MATCH (f:Foo)
WITH f, TOINTEGER(apoc.text.regexGroups(f.name, '\\d+')[0][0]) AS acct
WITH acct, COLLECT(f) AS foos
WHERE SIZE(foos) > 1
CALL apoc.refactor.mergeNodes(foos) YIELD node
RETURN acct