File: m4.info, Node: Regexp, Next: Substr, Prev: Index macro, Up: Text handling 11.3 Searching for regular expressions ====================================== Searching for regular expressions is done with the builtin ‘regexp’: -- Builtin: regexp(STRING, REGEXP, [REPLACEMENT]) Searches for REGEXP in STRING. The syntax for regular expressions is closest to older GNU Emacs (grouping via ‘\(’ and ‘\)’, alternation via ‘\|’, one-or-more matching via ‘+’, zero-or-one matching via ‘?’), although for backwards compatibility reasons, M4 1.4.x does not enable intervals (that is, both ‘{’ and ‘\{’ match a literal ‘{’), nor character classes (that is, ‘[[:alpha:]]’ matches a sequence of one of six bytes followed by a literal close bracket, rather than all letters, the same as ‘[[ahlp:]’ followed by ‘]’). *Note Syntax of Regular Expressions: (emacs)Regexps. Support for intervals, character classes, non-greedy matches, or even alternative regular expression syntax (such as POSIX Basic or Extended Regular Expressions) are likely to be added in a future version of GNU M4. If REPLACEMENT is omitted, ‘regexp’ expands to the index of the first match of REGEXP in STRING. If REGEXP does not match anywhere in STRING, it expands to -1. If REPLACEMENT is supplied, and there was a match, ‘regexp’ changes the expansion to this argument, with ‘\N’ substituted by the text matched by the Nth parenthesized sub-expression of REGEXP, up to nine sub-expressions. The escape ‘\&’ is replaced by the text of the entire regular expression matched. For all other characters, ‘\’ treats the next character literally. A warning is issued if there were fewer sub-expressions than the ‘\N’ requested, or if there is a trailing ‘\’. If there was no match, ‘regexp’ expands to the empty string. The macro ‘regexp’ is recognized only with parameters. regexp(`GNUs not Unix', `\<[a-z]\w+') ⇒5 regexp(`GNUs not Unix', `\