Re: Regex introduction?
Joachim Katzer <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <1385584658.4346.16.camel@machtnix> |
>
> It seems only YAP and XSB provide regular expressions as a native
> feature. YAP based on Henry Spencer's library and XSB on POSIX 2 regex
> support.
>
> Did I miss something? Any precedence of well balanced interfaces for
> Prolog? The YAP interface is rather limited. The XSB one is richer,
> but a bit weird due to issues with atom-GC in XSB you should not be
> bothered with as a user.
IF-Prolog (5.1) did provide native (Basic POSIX-2) regexp support:
Syntax
regexp( +RegExp, +Atom )
regexp( +RegExp, +Atom, ?List )
Description
The predicates regexp/2/3 match Atom the regular expression RegExp. The
predicates succeed when Atom or a subatom of Atom matches RegExp,
otherwise they fail. With regexp/3 the matching subatoms of Atom can be
retrieved in List.
RegExp can be formed as follows:
c The character c where c is not a special character.
\c The character c where c is any character, except a digit in
the
range 1 - 9.
^ The beginning of the atom compared.
$ The end of the atom compared.
. Any character in the atom.
[s] Any character in the set s, where s is a character and/or a
range,
e.g. [c-f].
[^s] Any character not in the set s, where s is defined as above.
r* Zero or more successive occurrences of the regular
expression r. The
longest match is chosen.
rx The occurrence of regular expression r followed by the
occurrence of
regular expression x (Concatenation).
r\{m; n\} Any number of m through n successive occurrences of the
regular
expression r. The regular expression r\{m\} matches exactly
m
occurrences, r\{m,\} matches at least m occurrences.
\(r\) The subatom matching the regular expression r is returned in
the
result list List.
Arguments
RegExp Atom, a regular expression
Atom Atom
List List of atoms
Exceptions
type_error(atom)
The argument RegExp must be an atom, but is a term of another type.
type_error(atom)
The argument Atom must be an atom, but is a term of another type.
type_error(list)
The argument List must be a list, but is a term of another type.
type_error(atom)
An element of List must be an atom, but is a term of another type.
domain_error(Description)
The argument RegExp is not a legal regular expression. Description
is a
closer description of the error.