[ library(regex) | Reference Manual | Alphabetic Index ]

matchall(+Pattern, +String, +Options, -AllMatches)

AllMatches is a list of substrings of String which match the regular expression Pattern
Pattern
A string (or a compiled pattern handle)
String
A string
Options
List of atoms
AllMatches
Output: List of strings

Description

This predicates always succeeds.

Options is a (possibly empty) list of atomic option names, as described in the library(regex) page.

AllMatches is bound to a list of strings. If the input string String does not match the pattern, the list is empty. Otherwise the list contains substrings of String which match the entire pattern, ordered according to their occurrence within String. No overlapping matches are returned, i.e. the next match is found by examining the remainder of String after the previous match.

Note that this predicate does not return any information about matching (parenthesised) sub-expressions!

Modes and Determinism

Fail Conditions

None

Examples

    ?- matchall("[0-9]+", " blue 27 red123 green99", [], L).
    L = ["27", "123", "99"]
    Yes

    ?- matchall("([0-9]+|[^0-9]+)", " blue 27 red123 green99", [], L).
    L = [" blue ", "27", " red", "123", " green", "99"]
    Yes
    

See Also

library(regex), match / 2, match / 3, match / 4, split / 4, compile_pattern / 3