Skip to content

String operators

Name Description
+ concatenating strings
CONTAINS Perform case-sensitive inclusion searching in strings
(NOT) IN Whether a value is within a set of values
(NOT) STARTS WITH Perform case-sensitive matching on the beginning of a string
(NOT) ENDS WITH Perform case-sensitive matching on the ending of a string
Regular expressions Perform regular expression matching on a string

NOTE: All the string matchings are case-sensitive.

Examples

  • concatenation (+)
nebula> RETURN 'a' + 'b';
+-------+
| (a+b) |
+-------+
| "ab"  |
+-------+
nebula> UNWIND 'a' AS a UNWIND 'b' AS b RETURN a + b;
+-------+
| (a+b) |
+-------+
| "ab"  |
+-------+
  • CONTAINS

The CONTAINS operator requires string type in both left and right side.

nebula> MATCH (s:player)-[e:serve]->(t:team) WHERE id(s) == "player101" \
    AND t.name CONTAINS "ets" RETURN s.name, e.start_year, e.end_year, t.name;
+---------------+--------------+------------+-----------+
| s.name        | e.start_year | e.end_year | t.name    |
+---------------+--------------+------------+-----------+
| "Tony Parker" | 2018         | 2019       | "Hornets" |
+---------------+--------------+------------+-----------+

nebula> GO FROM "player101" OVER serve WHERE (STRING)serve.start_year CONTAINS "19" AND \
    $^.player.name CONTAINS "ny" \
    YIELD $^.player.name, serve.start_year, serve.end_year, $$.team.name;
+----------------+------------------+----------------+--------------+
| $^.player.name | serve.start_year | serve.end_year | $$.team.name |
+----------------+------------------+----------------+--------------+
| "Tony Parker"  | 1999             | 2018           | "Spurs"      |
+----------------+------------------+----------------+--------------+

nebula> GO FROM "player101" OVER serve WHERE !($$.team.name CONTAINS "ets") \
    YIELD $^.player.name, serve.start_year, serve.end_year, $$.team.name;
+----------------+------------------+----------------+--------------+
| $^.player.name | serve.start_year | serve.end_year | $$.team.name |
+----------------+------------------+----------------+--------------+
| "Tony Parker"  | 1999             | 2018           | "Spurs"      |
+----------------+------------------+----------------+--------------+
  • IN
nebula> RETURN  1 IN [1,2,3], "Yao" IN ["Yi", "Tim", "Kobe"], NULL in ["Yi", "Tim", "Kobe"]
+----------------+--------------------------------+-------------------------------+
| (1 IN [1,2,3]) | ("Yao" IN ["Yi","Tim","Kobe"]) | (NULL IN ["Yi","Tim","Kobe"]) |
+----------------+--------------------------------+-------------------------------+
| true           | false                          | false                         |
+----------------+--------------------------------+-------------------------------+
  • (NOT) STARTS WITH
nebula> RETURN 'apple' STARTS WITH 'app', 'apple' STARTS WITH 'a', 'apple' STARTS WITH toUpper('a')
+-----------------------------+---------------------------+------------------------------------+
| ("apple" STARTS WITH "app") | ("apple" STARTS WITH "a") | ("apple" STARTS WITH toUpper("a")) |
+-----------------------------+---------------------------+------------------------------------+
| true                        | true                      | false                              |
+-----------------------------+---------------------------+------------------------------------+

nebula> RETURN 'apple' STARTS WITH 'b','apple' NOT STARTS WITH 'app'
+---------------------------+---------------------------------+
| ("apple" STARTS WITH "b") | ("apple" NOT STARTS WITH "app") |
+---------------------------+---------------------------------+
| false                     | false                           |
+---------------------------+---------------------------------+
  • (NOT) ENDS WITH
nebula> RETURN 'apple' ENDS WITH 'app', 'apple' ENDS WITH 'e', 'apple' ENDS WITH 'E', 'apple' ENDS WITH 'b'
+---------------------------+-------------------------+-------------------------+-------------------------+
| ("apple" ENDS WITH "app") | ("apple" ENDS WITH "e") | ("apple" ENDS WITH "E") | ("apple" ENDS WITH "b") |
+---------------------------+-------------------------+-------------------------+-------------------------+
| false                     | true                    | false                   | false                   |
+---------------------------+-------------------------+-------------------------+-------------------------+
  • Regular expressions

Nebula Graph supports filtering by using regular expressions. The regular expression syntax is inherited from std::regex. You can match on regular expressions by using =~ 'regexp'. For example:

nebula> RETURN "384748.39" =~ "\\d+(\\.\\d{2})?";
+----------------------------+
| (384748.39=~\d+(\.\d{2})?) |
+----------------------------+
| true                       |
+----------------------------+
nebula> MATCH (v:player) WHERE v.name =~ 'Tony.*' RETURN v.name;
+---------------+
| v.name        |
+---------------+
| "Tony Parker" |
+---------------+

NOTE: Regular expressions CAN NOT work with nGQL-extensions (GO/FETCH clause will return syntax error). Use it in openCypher only (e.g., in MATCH-WHERE clause).


Last update: March 23, 2021
Back to top