Seth Woolley's Man Viewer

Manual for regexp - man n regexp

([section] manual, -k keyword, -K [section] search, -f whatis)
man plain no title

regexp(3,n)(n)                    Tcl Built-In Commands                   regexp(3,n)(n)



NAME
       regexp(3,n) - Match a regular expression against a string(3,n)


SYNOPSIS
       regexp(3,n) ?switches? exp string(3,n) ?matchVar? ?subMatchVar subMatchVar ...?


DESCRIPTION
       Determines  whether  the  regular expression exp matches part or all of
       string(3,n) and returns 1 if(3,n) it does, 0 if(3,n) it  doesn't,  unless  -inline  is
       specified  (see  below).   (Regular expression matching is described in(1,8)
       the re_syntax reference page.)

       If additional arguments  are  specified  after  string(3,n)  then  they  are
       treated  as the names of variables in(1,8) which to return information about
       which part(s) of string(3,n) matched exp.  MatchVar will be set(7,n,1 builtins) to the range
       of  string(3,n) that matched all of exp.  The first subMatchVar will contain
       the characters in(1,8) string(3,n) that matched the leftmost parenthesized subex-
       pression  within  exp, the next subMatchVar will contain the characters
       that matched the next parenthesized subexpression to the right in(1,8)  exp,
       and so on.

       If  the  initial arguments to regexp(3,n) start with - then they are treated
       as switches.  The following switches are currently supported:

       -about         Instead of attempting to match the  regular  expression,
                      returns  a list containing information about the regular
                      expression.  The first element of the list is  a  subex-
                      pression  count.   The second element is a list of prop-
                      erty names that describe various attributes of the regu-
                      lar  expression.  This  switch(1,n) is primarily intended for
                      debugging purposes.

       -expanded      Enables use of the expanded  regular  expression  syntax
                      where  whitespace and comments are ignored.  This is the
                      same as specifying the (?x)  embedded  option  (see  the
                      re_syntax manual page).

       -indices       Changes  what is stored in(1,8) the subMatchVars.  Instead of
                      storing the matching characters from string(3,n), each  vari-
                      able  will  contain a list of two decimal strings giving
                      the indices in(1,8) string(3,n) of the first and  last  characters
                      in(1,8) the matching range of characters.

       -line          Enables newline-sensitive matching.  By default, newline
                      is a completely ordinary character with no special mean-
                      ing.   With  this flag, `[^' bracket expressions and `.'
                      never match newline, `^' matches an empty  string(3,n)  after
                      any  newline in(1,8) addition to its normal function, and `$'
                      matches an empty string(3,n) before any newline  in(1,8)  addition
                      to  its  normal  function.   This  flag is equivalent to
                      specifying both -linestop and -lineanchor, or  the  (?n)
                      embedded option (see the re_syntax manual page).

       -linestop      Changes the behavior of `[^' bracket expressions and `.'
                      so that they stop at newlines.   This  is  the  same  as
                      specifying  the  (?p) embedded option (see the re_syntax
                      manual page).

       -lineanchor    Changes the behavior of `^' and `$' (the ``anchors'') so
                      they match the beginning and end of a line respectively.
                      This is the same as specifying the (?w) embedded  option
                      (see the re_syntax manual page).

       -nocase        Causes  upper-case characters in(1,8) string(3,n) to be treated as
                      lower case during the matching process.

       -all           Causes the regular expression  to  be  matched  as  many
                      times  as  possible  in(1,8)  the string(3,n), returning the total
                      number of matches found.   If  this  is  specified  with
                      match  variables,  they will contain information for the
                      last match only.

       -inline        Causes the command to return, as a list, the  data  that
                      would  otherwise  be  placed  in(1,8)  match variables.  When
                      using -inline, match variables may not be specified.  If
                      used  with  -all,  the list will be concatenated at each
                      iteration, such that a flat  list  is  always  returned.
                      For  each  match  iteration, the command will append the
                      overall match data, plus one element for each subexpres-
                      sion in(1,8) the regular expression.  Examples are:
                          regexp(3,n) -inline -- {\w(\w)} " inlined "
                       => {in(1,8) n}
                          regexp(3,n) -all -inline -- {\w(\w)} " inlined "
                       => {in(1,8) n li i ne e}

       -start index   Specifies  a  character  index offset into the string(3,n) to
                      start matching the regular expression  at.   When  using
                      this  switch(1,n),  `^'  will  not match the beginning of the
                      line, and \A will still match the start of the string(3,n) at
                      index.   If  -indices  is specified, the indices will be
                      indexed starting from  the  absolute  beginning  of  the
                      input  string.   index will be constrained to the bounds
                      of the input string.

       --             Marks the end of switches.  The argument following  this
                      one will be treated as exp even if(3,n) it starts with a -.

       If  there  are  more  subMatchVar's  than  parenthesized subexpressions
       within exp, or if(3,n) a particular subexpression in(1,8) exp doesn't  match  the
       string(3,n)  (e.g. because it was in(1,8) a portion of the expression that wasn't
       matched), then the corresponding subMatchVar will be set(7,n,1 builtins) to  ``-1  -1''
       if(3,n) -indices has been specified or to an empty string(3,n) otherwise.


SEE ALSO
       re_syntax(n), regsub(n)


KEYWORDS
       match, regular expression, string(3,n)



Tcl                                   8.3                            regexp(3,n)(n)

References for this manual (incoming links)