Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
10-29-2020 11:44 AM
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,
Robert
10-29-2020 12:47 PM
if the order is always the same then how about split?
something like this lovely hack ( with all it's pitfalls )
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
11-03-2020 06:24 AM
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,
11-04-2020 08:53 AM
sry for the late response
did you ever take a look at the apoc text regex functions?
apoc.text
more examples
11-04-2020 08:58 AM
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]
11-05-2020 08:36 AM
don't you need to add * after the dot?
AND t.ProductName =~ "L.*"
11-05-2020 08:41 AM
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.
11-05-2020 08:53 AM
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.
11-05-2020 08:57 AM
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)
11-05-2020 08:59 AM
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
All the sessions of the conference are now available online