Characters in Neo4j neopagan regex

I store email addresses in some custom nodes that I am trying to match, however the (?i)

case-insensitive setting does not work if added to the mailing address +

, I use them for testing, for example john+business@doe.com

.

Test node setup:

CREATE (uWithoutSymbol:USER {
    email: 'john@doe.com'
})
CREATE (uWithSymbol:USER {
    email: 'john+business@doe.com'
})

      

Cypher Queries:

MATCH (u:USER)
// This works
WHERE u.email =~ '(?i)john@doe.com'
RETURN u

MATCH (u:USER)
// This returns nothing
WHERE u.email =~ '(?i)john+business@doe.com'
RETURN u

      

I tried changing to unicode case insensitive: (?ui)

but also no luck. Any ideas?

+3


source to share


2 answers


The + plus character has special meaning in regular expressions; avoid this:

WHERE u.email =~ '(?i)john\\+business@doe.com'

      

The plus sign means "one or more of the previous terms", so your attempt will match "johnbusiness@doe.com"

or "johnnnnbusiness@doe.com"

.

Technically, you should also avoid the dot:



WHERE u.email =~ '(?i)john\\+business@doe\.com'

      

because without escaping the point it will match any character, for example it will match "john+business@doeAcom"

or "john+business@doe#com"

too.

Thanks to @Stefan for specifying the double backslash needed to create a single backslash for the regex

+3


source


@ Bohemian's answer solves the problem: you need to specify +

. But in Cypher, the backslash must be duplicated:

MATCH (u:USER)
WHERE u.email =~ '(?i)john\\+business@doe.com'
RETURN u

      



returns the desired result.

+2


source







All Articles