src/swipl-devel/packages/xpce/man/refmanual/md/regex.md

class regex {#class-regex}

Class regex implements regular-expression handling. A regular expression is a specification of a string with various wildcard mechanisms. It is compiled to a finite state machine which is executed to make the match. XPCE's regular expression use Henry Spencer's regex library, modified by the Tcl project to handle UNICODE and modified by us to deal with implementation details of class text_buffer and class char_array. Regular expressions can be used to search in one of the following objects:

The match is controlled by the following variables:

Example {#class-regex-example}

The following code searched for method references in the PCE documentation style.

find_method_ref(TextBuffer, Access, Method) :-
    new(R, regex('(->|<-|<->)(\w+)')),
    send(R, search, TextBuffer),
    get(R, register_value,
        1, TextBuffer, name, Arrow),
    get(R, register_value,
        2, TextBuffer, name, Method),
    map_arrow(Arrow, Access).

map_arrow(->, send).
map_arrow(<-, get).
map_arrow(<->, both).

Reusability note {#class-regex-reusability-note}

A regex object holds information about the last match. This information will be overwritten on a new ->match or ->search.

@see string->strip @see class text_buffer @see class char_array

Instance variables {#class-regex-instvars}

Send methods {#class-regex-send}

Get methods {#class-regex-get}



Try the rswipl package in your browser

Any scripts or data that you put into this service are public.

rswipl documentation built on June 16, 2026, 5:07 p.m.