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.

About pattern matching

I am trying to clean a string read from LOAD CSV using pattern matching.

The idea was to use the following query

RETURN apoc.text.replace('Aglianico Del Vulture DOC Serpara 2010 Re Manfredi
!', '([\s\S]*?)(DOCG|DOP|DOC|IGP|IGT)/mig', '') AS output;

The expected result (tested on regex101) should be

Aglianico Del Vulture  Serpara  Re Manfredi

But the result from apoc is the same as input with absolutely no change.

Can someone explain and suggest a way to solve the problem?

Thank you

1 ACCEPTED SOLUTION

Ciao @p.dipietro ,

You can always change the last with in order to include a whole list.

with "(DOCG|DOP|DOC|IGP|IGT)" as bList
with "Aglianico Del Vulture IGP DOC Serpara 2010 Re Manfredi
!" as strg1, bList
with apoc.text.replace(strg1, '[^a-zA-Z]', ' ') as strg, bList
return trim(apoc.text.replace(strg, bList, ' ')) as final

Btw, are you sure that your Regex worked on regex101?

H

View solution in original post

3 REPLIES 3

ameyasoft
Graph Maven
Try this:

with "Aglianico Del Vulture DOC Serpara 2010 Re Manfredi
!" as strg1
with apoc.text.replace(strg1, '[^a-zA-Z]', ' ') as strg
return apoc.text.replace(strg, 'DOC', ' ') as final

Thank you, but my problem is that I have different input strings, and must remove all the occurrences of DOCG|DOP|DOC|IGP|IGT case independently!

Ciao @p.dipietro ,

You can always change the last with in order to include a whole list.

with "(DOCG|DOP|DOC|IGP|IGT)" as bList
with "Aglianico Del Vulture IGP DOC Serpara 2010 Re Manfredi
!" as strg1, bList
with apoc.text.replace(strg1, '[^a-zA-Z]', ' ') as strg, bList
return trim(apoc.text.replace(strg, bList, ' ')) as final

Btw, are you sure that your Regex worked on regex101?

H