Does Apache Age support opencypher queries with full regular expressions? I know you can use “.”, “*”, ”+”… but can full regex be used in comparison operators like =~
, string functions like replace()
etc…
10 Answers
Yes, Cypher queries in Apache AGE support operators like =~
and replace()
function. For example, suppose you have the following data setup:
SELECT * FROM cypher('graph_name', $$
CREATE (:Person {name: 'John'}),
(:Person {name: 'Jeff'}),
(:Person {name: 'Joan'}),
(:Person {name: 'Bill'})
$$) AS (result agtype);
You can combine =~
with the .
operator to match any character:
SELECT * FROM cypher('graph_name', $$
MATCH (v:Person)
WHERE v.name =~ 'Jo.n'
RETURN v.name
$$) AS (names agtype);
names
"John"
"Joan"
2 rows
Refer to the documentation for Operators and String Functions.

- 326
- 1
- 7
You can use the =~
operator with various regex such as:
SELECT *
FROM cypher('graph_name', $$
MATCH (n:Person)
WHERE n.name =~ '(?i)TIM.*'
RETURN n.name
$$) as (name agtype);
which will return the names starting with the characters 'Tim' (case-insensitive) of nodes labelled 'Person'. Take a look at the Regular expressions section of the Neo4j documentation.
And the replace()
function as such:
SELECT *
FROM cypher('graph_name', $$
RETURN replace('identifier.expression', '.', '_')
$$) as (v agtype);
which will return
v
-------------------------
"identifier_expression"
(1 row)

- 397
- 1
- 13
Yes, AGE does support =~
operator for string matching with regex. But not all regex patterns are allowed.
AGE utilizes PostgreSQL's textregexeq
function to handle regular expressions. This function is based on POSIX style regex, which means that you cannot use Python-like regex that supports both POSIX and non-POSIX expressions.
For instance, if you try to use the following regex:
SELECT * FROM cypher('sample_graph', $$
RETURN 'john.doe@example.co.uk' =~ '^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$'
$$) AS (r agtype);
You will encounter an error: invalid escape sequence at or near '\w'. This pattern works fine in languages like Python but not in PostgreSQL because '\w' is non-POSIX.
However, the following pattern will work:
SELECT * FROM cypher('sample_graph', $$
RETURN 'thomas' =~ 't.*ma'
$$) AS (r agtype);
This query will return a result of 'true'.
If you want more info about regular expressions in AGE, you can visit the PostgreSQL regex page.

- 433
- 9
If by "full regex" in your question, you mean the regex used in Python or Java, then the answer is No. AGE relies on PostgreSQL, which only supports the POSIX standard for regex. Therefore, any identifier that does not conform to the POSIX standard is not allowed. You can learn more about the POSIX standard here.
Yes they are supported, a simple match pattern example:
MATCH (n)
WHERE n.name =~ 'J.*'
RETURN n
This query will match all nodes where the "name" property starts with "J".

- 142
- 6
Yes, Apache AGE supports the use of =~
to match patterns in a query, for example;
SELECT *
FROM cypher ( 'your_graph', $$
MATCH (a:Person)
WHERE a.name=~'Pete'
RETURN a
$$) AS (a agtype);
and this query will return all names with the same pattern as 'Pete' such as Pete, Peter, Peters, Peterson etc.

- 333
- 1
- 7
AGE extension does offer support for the =~
operator, enabling string matching using regular expressions.
For example consider the following query:
SELECT *
FROM cypher('Info_table', $$
MATCH (n:User)
WHERE n.email =~ '(?i)@gmail.*'
RETURN n.email
$$) AS (email agtype);
This query will retrieve email with the characters '@gmail'. But keep in mind not all regex are permitted or supported within the AGE extension. Hence, it is best to consult the documentation in this regard.

- 43
- 5
Yes, Apache age supports OpenCypher queries with full regular expression.
You can use =~ expression to compare string with regular expression pattern such as name=~'A.*'
.
You can read in official PostgreSQL Blog.

- 3
- 8
Apache AGE supports a subset of cypher query language. It does support the
=~
expression however, not all cypher queries are supported and you may need to refer to the official documentation for specific details.

- 205
- 2
Yes, Apache AGE supports both regex and string functions like replace.
For regex:
SELECT * FROM cypher ( 'graph', $$
MATCH (a)
WHERE a.value=~'[a-z] {4}'
RETURN a
$$) AS (a agtype);
For replace:
SELECT * FROM cypher('graph', $$
MATCH (a)
RETURN replace(a.name, 'a', 'b')
$$) as (v agtype);
For more details, check this string functions

- 312
- 1
- 11