apoc.text.regexGroupsByName

详细信息

语法

apoc.text.regexGroupsByName(text, regex)

描述

返回给定文本中与正则表达式匹配的所有命名分组及其内容。

参数

名称

类型

描述

文本 (text)

STRING

要从中提取匹配项的文本。

regex

STRING

用于匹配的正则表达式模式。

返回

LIST<MAP>

输出值为一个 LIST<MAP>,其中包含一个 group 字段(值为完整匹配项)以及一个 matches 字段(其本身为一个 MAP,包含每个组名称及其对应的值)。

{
    group: <groupMatched>,
    matches: {
                <groupName>: <match>, ...
            }
}

使用示例

RETURN apoc.text.regexGroupsByName(
  'abc <link xxx1>yyy1</link> def <link xxx2>yyy2</link>',
  '<link (?<firstPart>\\w+)>(?<secondPart>\\w+)</link>'
) AS output;
结果
输出

[{ "group": "<link xxx1>yyy1</link>", "matches" : {"firstPart": "xxx1", "secondPart": "yyy1"}}, {"group": <link xxx2>yyy2</link>", "matches" : { "firstPart": "xxx2", "secondPart": "yyy2"}}]

RETURN apoc.text.regexGroups(
  'Michael: 1234\nJennifer: 5678',
  '(?<name>\\w+): (?<id>\\d+)'
) AS output;
结果
输出

[ { "group": "Michael: 1234", "matches": { "name": "Michael", "id": "1234" }, { "group": "Jennifer: 5678", "matches": { "name": "Jennifer", "id": "5678" } } ]