跳转至

字符串运算符

Nebula Graph 支持使用字符串运算符进行连接、搜索、匹配运算。支持的运算符如下。

名称 说明
+ 连接字符串。
CONTAINS 在字符串中执行搜索。
(NOT) IN 字符串是否匹配某个值。
(NOT) STARTS WITH 在字符串的开头执行匹配。
(NOT) ENDS WITH 在字符串的结尾执行匹配。
正则表达式 通过正则表达式匹配字符串。

Note

所有搜索或匹配都区分大小写。

示例

+

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

CONTAINS

CONTAINS要求待运算的左右两边都是字符串类型。

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

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

nebula> GO FROM "player101" OVER serve WHERE !(properties(\(\().name CONTAINS "ets") \ YIELD properties(\)^).name, properties(edge).start_year, properties(edge).end_year, properties(\)\().name; +---------------------+-----------------------------+---------------------------+---------------------+ | properties(\)^).name | properties(EDGE).start_year | properties(EDGE).end_year | properties($$).name | +---------------------+-----------------------------+---------------------------+---------------------+ | "Tony Parker" | 1999 | 2018 | "Spurs" | +---------------------+-----------------------------+---------------------------+---------------------+ ```

(NOT) IN

ngql nebula> RETURN 1 IN [1,2,3], "Yao" NOT IN ["Yi", "Tim", "Kobe"], NULL IN ["Yi", "Tim", "Kobe"]; +----------------+------------------------------------+-------------------------------+ | (1 IN [1,2,3]) | ("Yao" NOT IN ["Yi","Tim","Kobe"]) | (NULL IN ["Yi","Tim","Kobe"]) | +----------------+------------------------------------+-------------------------------+ | true | true | __NULL__ | +----------------+------------------------------------+-------------------------------+

(NOT) STARTS WITH

```ngql 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

ngql 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 | +---------------------------+-------------------------+-------------------------+-------------------------+

正则表达式

Note

当前仅 opencypher 兼容语句(MATCHWITH等)支持正则表达式,原生 nGQL 语句(FETCHGOLOOKUP等)不支持正则表达式。

Nebula Graph 支持使用正则表达式进行过滤,正则表达式的语法是继承自std::regex,用户可以使用语法=~ '<regexp>'进行正则表达式匹配。例如:

```ngql nebula> RETURN "384748.39" =~ "\d+(\.\d{2})?"; +--------------------------------+ | ("384748.39"=~"\d+(.\d{2})?") | +--------------------------------+ | true | +--------------------------------+

nebula> MATCH (v:player) WHERE v.player.name =~ 'Tony.*' RETURN v.player.name; +---------------+ | v.player.name | +---------------+ | "Tony Parker" | +---------------+ ```


最后更新: 2026年8月17日