Prolog and Regular Expressions
there is a very simple straightforward interface to the ISO regular
expression functions regcomp(3), regexec(3), regfree(3),
regerror(3). Tested for SICStus Prolog, should work for Prologs with
similar foreign language interface. GPL.
- two similar implementations are available from
- similar functionality is built-in in IF-Prolog, for info consult
- recent versions of YAP include a regular
- it's also present in XPCE, which is a graphical user-interface
sometimes used with SWI-Prolog.
- Ciao Prolog (Gnu-copyright) has a library for regular expression
- K-Prolog has regular expressions too. http://prolog.isac.co.jp/doc/en/feature/reg_match.html
- MINERVA has regular expressions too, cf
MINERVA (proprietory, commercial, ISO-Prolog compiler in 100% Java)
- there is also a large package with finite-state utilities, all
implemented in SICStus Prolog, called FSA Utilities. It contains a
regular expression compiler, all kinds of operations on finite
state acceptors, weighted finite-state acceptors and finite state
transducers. Operations include determinization, minimization,
visualization etc. There is support to add your own regular expression
operators. Etc. Etc.
The latest addition is a compiler of sequential (`deterministic') finite
state transducers into a C program which computes the transduction (line
by line). It's about 100 times faster than the built-in transduction
option of FSA. Available (GPL) from
there is a very small and very experimental web demo at
the user manual is available as
- another implementation of (extended) regular expressions in Prolog is
- XSB Prolog. There is a chapter in the XSB book on how to do
automata theory in XSB.
- A page entitled Perl Style Regular Expressions (in Prolog).
- if you're looking for a lex-like tool, you might consider Elex. Elex
is a lexical analyzer generator with multiple output languages. There
is a version which produces Prolog lexers at
The original Elex homepage is at
So this is not implemented in Prolog (in C++ and Perl, rather), but
can be made to produce Prolog output (tested with SICStus, SWI,
BinProlog, Bprolog; should work for others).
- another lexer with Prolog output (implemented in Prolog) is part
of multiplex by Peter Reintjes (for Quintus prolog).