apoc.text.regexGroupsByName

Details

Syntax

apoc.text.regexGroupsByName(text, regex)

Description

Returns all groups with their group name matching the regular expression in the given text.

Arguments

Name

Type

Description

text

STRING

The text to extract matches from.

regex

STRING

The regex pattern to match.

Returns

LIST<MAP>

The output value is a LIST<MAP> which contains a group field with the value being the complete match, and a matches field which itself is a MAP containing each group name mapped to its value.

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

Usage Examples

RETURN apoc.text.regexGroupsByName(
  'abc <link xxx1>yyy1</link> def <link xxx2>yyy2</link>',
  '<link (?<firstPart>\\w+)>(?<secondPart>\\w+)</link>'
) AS output;
Results
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;
Results
output

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