www.delorie.com/gnu/docs/m4/m4_53.html   search  
 
Buy GNU books!


GNU macro processor

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

10.3 Searching for regular expressions

Searching for regular expressions is done with the builtin regexp:

 
regexp(string, regexp, opt replacement)

which searches for regexp in string. The syntax for regular expressions is the same as in GNU Emacs. See section `Syntax of Regular Expressions' in The GNU Emacs Manual.

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.

 
regexp(`GNUs not Unix', `\<[a-z]\w+')
=>5
regexp(`GNUs not Unix', `\<Q\w*')
=>-1

If replacement is supplied, regexp changes the expansion to this argument, with `\n' substituted by the text matched by the nth parenthesized sub-expression of regexp, `\&' being the text the entire regular expression matched.

 
regexp(`GNUs not Unix', `\w\(\w+\)$', `*** \& *** \1 ***')
=>*** Unix *** nix ***

The builtin macro regexp is recognized only when given arguments.


  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003