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.

Regex matching "\text{Hom}(.+,.+)" does not work

Here's a screenshot showing everything:

As you can see my template_regex is:

\text\{Hom\}\(.+,.+\)

It's not matching either of the nodes shown in the lower right, but also shown in my front end (which I'm kind of showing off) here:

Those nodes exist in the Neo4j database, however, they're not being matched by this very basic regular expression.

Thanks in advance for your guidance.

1 ACCEPTED SOLUTION

def escape_regex_str(string):
    string = string.replace('\\', r'\\\\')
    string = string.replace("'", r"\'")
    string = string.replace('{', r'\{')
    string = string.replace('}', r'\}')
    string = string.replace('(', r'\(')
    string = string.replace(')', r'\)')
    return string

Fixed the problem by executing the query (copied from debug watcher in IDE) in Neo4j Desktop for better testing.

The top line of the above function solved the issue. Might be with t since escaping that is usually the tab character, so we need to double escape some of the backslashes. 🙂

View solution in original post

1 REPLY 1

def escape_regex_str(string):
    string = string.replace('\\', r'\\\\')
    string = string.replace("'", r"\'")
    string = string.replace('{', r'\{')
    string = string.replace('}', r'\}')
    string = string.replace('(', r'\(')
    string = string.replace(')', r'\)')
    return string

Fixed the problem by executing the query (copied from debug watcher in IDE) in Neo4j Desktop for better testing.

The top line of the above function solved the issue. Might be with t since escaping that is usually the tab character, so we need to double escape some of the backslashes. 🙂