cancel
Showing results for 
Search instead for 
Did you mean: 

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

fruitfulapproac
Graph Buddy

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

fruitfulapproac
Graph Buddy
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

fruitfulapproac
Graph Buddy
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. 🙂