Fuzzy query in cypher =~

Hi there ,

I encountered an issue about fuzzy query with cypher that puzzled me for one week.
If I'd like to query a person who has the skill contains C++ (ignore the upper case or lower case) , the query below runs well in desktop browser:
match p = (a:Person {user_id:'18501700312'})-[r0..2]->()-[r1]->(b:Person)
where r1.skill =~ '.
(?i)C++.*'

But it runs with error if I'd like to query a person who has the skill contains C+++ (ignore the upper case or lower case) ,

match p = (a:Person {user_id:'18501700312'})-[r0..2]->()-[r1]->(b:Person)
where r1.skill =~ '.
(?i)C+++.*'

Error msg :
ERROR Neo.ClientError.Statement.SemanticError
Invalid Regex: Dangling meta character '+' near index 9 .(?i)C+++.

I thought + is a special character in cypher , I tried to use escape sign (\) , it does not work well , who can help with this ? Any suggestion would be appreciated , looking forward to your feedback.

Try below query for C+++
match p = (a:Person {user_id:'18501700312'})-[r 0..2]->()-[r1]->(b:Person)
where r1.skill =~ '.*(?i)c\+{3}'
Note: There are two backslash rather than one. editor is not displaying it.
Updated the post to incorporate case insensitive

1 Like

Hi,

Here's an alternative.
It is easy to understand.

CREATE (:Person {name: 'John'})<-[:SKILL {skill: 'Python'}]-(),
       (:Person {name: 'Bob'})<-[:SKILL {skill: 'C'}]-(),
       (:Person {name: 'Jane'})<-[:SKILL {skill: 'C++'}]-(),
       (:Person {name: 'Lisa'})<-[:SKILL {skill: 'c++'}]-(),
       (:Person {name: 'Mike'})<-[:SKILL {skill: 'C+++'}]-(),
       (:Person {name: 'Will'})<-[:SKILL {skill: 'c+++'}]-()
MATCH (a:Person)<-[r1]-()
  WHERE toLower(r1.skill) CONTAINS toLower('C+++')
RETURN a.name, r1.skill

"C+++" and "c+++" are the return values.

a.name	r1.skill
"Mike"	"C+++"
"Will"	"c+++"
2 Likes

Really helpful , awesome , it works well , many thanks.

1 Like

Kindly mark the solution to close it

this works well also for this single case , thanks all the same

Really helpful , awesome , it works well , many thanks.

Could you please explain what do you mean by single case ? So that I can correct myself