GNU Info

Info Node: (librep.info)Regexp Functions

(librep.info)Regexp Functions


Prev: Regexp Syntax Up: Regular Expressions
Enter node , (file) or (file)node

Regexp Functions
----------------

   These functions are exported by the `rep.regexp' module.

 - Function: quote-regexp string
     Return a version of STRING, such that when used as a regexp, it
     will match the original contents of STRING verbatim, and nothing
     else. This involves quoting regexp meta-characters.

          (quote-regexp "abc")
              => "abc"
          
          (quote-regexp "a+c")
              => "a\\+c"

 - Function: string-match regexp string #!optional start ignore-case
     Returns true if the string STRING matches the regular expression
     REGEXP. The string matches if executing the regexp at _any_
     position in the string succeeds.

     When defined, START is the index of the first character to start
     matching at (counting from zero). When IGNORE-CASE is true the
     case of matched strings are ignored. Note that character classes
     are still case-significant.

          (string-match "ab+c" "abbbc")
              => t
          
          (string-match "ab+c" "xxxabbbcyyy")
              => t

 - Function: string-looking-at regexp string #!optional start
          ignore-case
     Similar to `string-match', but only returns true if STRING matches
     REGEXP starting at the character at index START in the string (or
     the first character if START is undefined).

          (string-looking-at "ab+c" "abbbc" 0)
              => t
          
          (string-looking-at "ab+c" "xxxabbbcyyy" 0)
              => ()
          
          (string-looking-at "ab+c" "xxxabbbcyyy" 3)
              => t

 - Function: match-start #!optional n
     Returns the position at which the N'th parenthesised expression
     started in the last successful regexp match. If N is false or zero
     the position of the start of the whole match is returned instead.

     When matching strings, all positions are integers, with the first
     character in the string represented by zero. However, extensions
     that allow regexps to be matched against other textual inputs may
     return different position values.

          (string-match "x*(foo|bar)y" "xxxbary")
              => t
          
          (match-start 1)
              => 3

 - Function: match-end #!optional n
     Similar to `match-start', but returns the position of the
     character following the matched item.

          (string-match "x*(foo|bar)y" "xxxbary")
              => t
          
          (match-end 1)
              => 6

   A common use of regular expressions is to match a string, then
replace certain portions of the string with other text.

 - Function: expand-last-match template
     Expand the TEMPLATE substituting the parenthesised expressions
     from the most recent successfully matched regular expression.

     TEMPLATE may contain the following substitution-inducing escape
     sequences:

    `\0'
    `\&'
          Substitute the whole string matched by the last regexp

    `\N'
          Substitute the N'th parenthensised expression, where 1 <= N
          <= 9.

    `\\'
          Substitute a single backslash character.

          (string-match "x*(foo|bar)y" "xxxbary")
              => t
          
          (expand-last-match "test-\\1-ing")
              => "test-bar-ing"

     Note that double backslashes are required due to the read syntax of
     strings (Note: Strings).

 - Function: string-replace regexp template string
     Returns the string created by replacing all matches of REGEXP in
     STRING with the result of expanding TEMPLATE using the
     `expand-last-match' function.

          (string-replace "-" "_" "foo-bar-baz")
              => "foo_bar_baz"
          
          (string-replace "&(optional|rest)" "#!\\1" "(a &optional b &rest c)")
              => "(a #!optional b #!rest c)"


automatically generated by info2www version 1.2.2.9