Function | Package: excl | ToC | DocOverview | CGDoc | RelNotes | FAQ | Index | PermutedIndex
| Allegro CL version 9.0 Unrevised from 8.2 to 9.0. 8.2 version

## re-submatch

Arguments: regexp string indexes selector &key (type :string)

This is a convenience function to extract a specified submatch information from the value returned by match-re.

regexp should be a compiled regexp, and indexes should be a list of `(start . end)` index pairs returned by match-re. selector should be an integer that specifies a captured submatch (or 0 for the whole match), or a string or a symbol that names a named submatch.

Alternatively, you can pass the opaque 'match' object returned by match-re with `:return :match` argument, as regexp. The match object knows the information about the match results, so you don't need string and indexes; just pass `nil` to them.

The type argument may be `:string`, `:after`, `:before` or `:index`. It specifies the return value. If it is :string (the default), the substring of the specified submatch is returned. If it is `:after` or `:before`, the substring after or before the specified submatch is returned, respectively. If it is `:index`, a pair of `(start . end)` indexes are returned.

If the specified submatch isn't included in indexes, `nil` is returned.

A typical usage pattern of this function is like this:

    (let ((r (multiple-value-list (match-re regexp string :return :index))))
      (re-submatch regexp string (cdr r) 3)))

Or, if you use the match object, like this:

    (let ((match (match-re regexp string :return :match)))
      (re-submatch match nil nil 3))

### Additional examples

    cl-user(25): (let* ((s "abCDEfg")
                        (x (compile-re "[A-Z]([A-Z]+)"))
                        (r (cdr (multiple-value-list
                                 (match-re x s :return :index)))))
                   (list
                    (re-submatch x s r 0)
                    (re-submatch x s r 1)
                    (re-submatch x s r 0 :type :before)
                    (re-submatch x s r 1 :type :before)
                    (re-submatch x s r 0 :type :after)
                    (re-submatch x s r 1 :type :after)))
    ("CDE" "DE" "ab" "abC" "fg" "fg")
    cl-user(26):

The symbol naming this operator is also exported from the regexp package.

See The new regexp2 module in regexp.htm for further information on this function and the regexp2 module.

Copyright (c) 1998-2019, Franz Inc. Oakland, CA., USA. All rights reserved.
This page was not revised from the 8.2 page.
Created 2012.5.30.

|  | ToC | DocOverview | CGDoc | RelNotes | FAQ | Index | PermutedIndex
| Allegro CL version 9.0 Unrevised from 8.2 to 9.0. 8.2 version