Extract number from node and add to new property

Hello Everyone,

I have the situation where I have a property on a node named : ProductName.
And the property is: City 60057 Great Vehicles Camper Van

I want to extract the numbers and put it in it'sown field named Product_code, but also I want to extract the word city and put it in a field named : Theme.

Then remove those values from that property. I was seeing if I could use regEx, but the instructions on the web is realy vague on the use of Regex in Neo4j, but also the second problem is I don't quite understand how to have that selected data written to a property.

My first thought is that "SET" will have to be used in this problem, but not sure how to select only the stuff I need to give to "SET".

Thank in advance,

if the order is always the same then how about split?
something like this lovely hack ( with all it's pitfalls ) :slight_smile:

match (p:ProductName)
with p, split(p.myProperty,' ') as words
set p.Product_code = words[1]
set p.Theme = words[0]
set p.myProperty = trim(replace(replace(p.myProperty,words[0],''),words[1],''))
return p

Hello Vizipi,

Thank you for this solution. Do you know where I can find clear explanation on how to use REGEX in Neo4j ? the manual doesn't cover it all all, just quick mentions of how it looks, but no clear usage steps.

Kind regards,

sry for the late response
did you ever take a look at the apoc text regex functions?
more examples

Hello Vizipi,

I didn't even know those existed.

apoc.text.regexGroups(text, regex)
apoc.text.regreplace(text, regex, replacement)

Can you tell me why the following doesn't work? There are products with the product name LEGO in the beginning.

MATCH (t:Toy)
WHERE t.ProductName contains "Juniors" AND t.ProductName =~ "L."
WITH t, SPLIT(t.ProductName, " ") AS words

return t, t.ModelNr, words[2]

don't you need to add * after the dot?

AND t.ProductName =~ "L.*"

Ok, let me try that. I am just learning RegEx. There so little information on how to use RegEx in Neo4j.
Can you use RegEx to select the the text and pipe it to a SET clause to fill a property? That would be perfect.

So the match from regex as the property value used for the SET clause.

excellent place to "learn" and test regex online

Thank you for that link.

One question is there something that can do the following?
MATCH (t:Toy {SalesRank:max (85000) } )

I am trying to do a sort of where in the property field.

Are you trying to get Toys ordered by SalesRank? ( i don't know that you can put the where clause the way you typed it above )
might be easier to move this to slack (neo4j-users)

slack (neo4j-users) ? Can you explain what makes that group more appropriate? I take it that it is a another group here on the forum.

To match on all toys that are at a max amount of a given nr.

I think it can be done with a where clause after the match, so WHERE t.Salesrank < 85000 as p