Is there a way to escape regex metacharacters (. + * ? etc) in a Cypher query? I want to do something like this:
MATCH (n), (m)
WHERE n.name =~ '.*\b' + m.name + '\b.*'
However there will be a problem if m.name happens to contain metacharacters, so I would like to call a function/procedure which would escape them before doing the regex operation, something like the quotemeta() function in Perl.
WITH "Here is (my) * test string? with some + meta." as mystring
WITH *,["[","]","(" ,")", "?" ,"+" , "*" ,"."] as regexmetachars
WITH *,reduce(v = mystring, char in regexmetachars | apoc.text.replace(v, '[\\'+char+']{1}', '\\\\'+char)) as filteredstring
RETURN mystring,filteredstring
How would one want to do this same approach if the character in question is ". I am streaming in some raw data with apoc.periodic.iterate and apoc.load.csv and I know the data can have some misc ' and " in there. Any thoughts?
I did think of the second recommendation last night after sending my message. Still ran into an issue, but I am working to figure that out. Will post once I figure out my issue.