Version: v0.7.0 - Beta.  We welcome contributors & feedback.

String.matchAll

matchAll($regexPattern, $groupNames = '') -> list

Description

Apply a regex pattern and return a List of all matches.

If there are no matches, it returns an empty List [].

Each match value behaves like the match method. If there are capture groups defined by parens (...), it will be a Map of captured values. Otherwise it will be a string of the entire match.

'red, green, blue'.matchAll(r'\w+')
//= ['red', 'green', 'blue']

'abc def'.matchAll(r'\d+')
//= []

'a:123, z:789'.matchAll(r'(\w):(\d+)', 'letter|number')
// [
//    {
//        full: 'a:123',
//        letter: 'a',
//        number: '123',
//    },
//    {
//        full: 'z:789',
//        letter: 'z',
//        number: '789',
//    }
// ]

See Also