Navigation

Operators and Keywords

Function List:

C++ API

regexp.cc File Reference

#include <algorithm>
#include <sstream>
#include "defun-dld.h"
#include "error.h"
#include "gripes.h"
#include "oct-obj.h"
#include "utils.h"
#include "Cell.h"
#include "oct-map.h"
#include "str-vec.h"
#include "quit.h"
#include "parse.h"
#include "oct-locbuf.h"
Include dependency graph for regexp.cc:

Classes

class  regexp_elem

Defines

#define PCRE_MATCHLIMIT_MAX   10
#define MAXLOOKBEHIND   10

Typedefs

typedef std::list< regexp_elem >
::const_iterator 
const_iterator

Functions

 DEFUN_DLD (regexp, args, nargout,"-*- texinfo -*-\n\ @deftypefn {Loadable Function} {[@var{s}, @var{e}, @var{te}, @var{m}, @var{t}, @var{nm}] =} regexp (@var{str}, @var{pat})\n\ @deftypefnx {Loadable Function} {[@dots{}] =} regexp (@var{str}, @var{pat}, \"@var{opt1}\", @dots{})\n\ Regular expression string matching. Search for @var{pat} in @var{str} and\n\ return the positions and substrings of any matches, or empty values if there\n\ are none. Note, some features and extended options are only available when\n\ Octave is compiled with support for Perl Compatible Regular Expressions\n\ (PCRE).\n\ \n\ The matched pattern @var{pat} can include any of the standard regex\n\ operators, including:\n\ \n\ @table @code\n\ @item .\n\ Match any character\n\ \n\ @item * + ? @{@}\n\ Repetition operators, representing\n\ @table @code\n\ @item *\n\ Match zero or more times\n\ \n\ @item +\n\ Match one or more times\n\ \n\ @item ?\n\ Match zero or one times\n\ \n\ @item @{@var{n}@}\n\ Match exactly @var{n} times\n\ \n\ @item @{@var{n},@}\n\ Match @var{n} or more times\n\ \n\ @item @{@var{m},@var{n}@}\n\ Match between @var{m} and @var{n} times\n\ @end table\n\ \n\ @item [@dots{}] [^@dots{}]\n\ \n\ List operators. The pattern will match any character listed between \"[\"\n\ and \"]\". If the first character is \"^\" then the pattern is inverted and\n\ any character except those listed between brackets will match.\n\ \n\ With PCRE support, escape sequences defined below can be used inside list\n\ operators. For example, a template for a floating point number might be\n\ @code{[-+.\\d]+}. POSIX regular expressions do not use escape sequences\n\ and any backslash @samp{\\} will be interpreted literally as one\n\ of the list of characters to match.\n\ \n\ @item ()\n\ Grouping operator\n\ \n\ @item |\n\ Alternation operator. Match one of a choice of regular expressions. The\n\ alternatives must be delimited by the grouping operator @code{()} above.\n\ \n\ @item ^ $\n\ Anchoring operators. Requires pattern to occur at the start (@code{^}) or\n\ end (@code{$}) of the string.\n\ @end table\n\ \n\ In addition, the following escaped characters have special meaning. Note,\n\ it is recommended to quote @var{pat} in single quotes, rather than double\n\ quotes, to avoid the escape sequences being interpreted by Octave before\n\ being passed to @code{regexp}.\n\ \n\ @table @code\n\ @item \\b\n\ Match a word boundary\n\ \n\ @item \\B\n\ Match within a word\n\ \n\ @item \\w\n\ Match any word character\n\ \n\ @item \\W\n\ Match any non-word character\n\ \n\ @item \<\n\ Match the beginning of a word\n\ \n\ @item \>\n\ Match the end of a word\n\ \n\ @item \\s\n\ Match any whitespace character\n\ \n\ @item \\S\n\ Match any non-whitespace character\n\ \n\ @item \\d\n\ Match any digit\n\ \n\ This sequence is only available with PCRE support. For POSIX regular\n\ expressions use the following list operator @code{[0-9]}.\n\ \n\ @item \\D\n\ Match any non-digit\n\ \n\ This sequence is only available with PCRE support. For POSIX regular\n\ expressions use the following list operator @code{[^0-9]}.\n\ @end table\n\ \n\ The outputs of @code{regexp} default to the order given below\n\ \n\ @table @var\n\ @item s\n\ The start indices of each matching substring\n\ \n\ @item e\n\ The end indices of each matching substring\n\ \n\ @item te\n\ The extents of each matched token surrounded by @code{(@dots{})} in\n\ @var{pat}\n\ \n\ @item m\n\ A cell array of the text of each match\n\ \n\ @item t\n\ A cell array of the text of each token matched\n\ \n\ @item nm\n\ A structure containing the text of each matched named token, with the name\n\ being used as the fieldname. A named token is denoted by\n\ @code{(?<name>@dots{})} and is only available with PCRE support.\n\ @end table\n\ \n\ Particular output arguments, or the order of the output arguments, can be\n\ selected by additional @var{opt} arguments. These are strings and the\n\ correspondence between the output arguments and the optional argument\n\ are\n\ \n\ @multitable @columnfractions 0.2 0.3 0.3 0.2\n\ @item @tab 'start' @tab @var{s} @tab\n\ @item @tab 'end' @tab @var{e} @tab\n\ @item @tab 'tokenExtents' @tab @var{te} @tab\n\ @item @tab 'match' @tab @var{m} @tab\n\ @item @tab 'tokens' @tab @var{t} @tab\n\ @item @tab 'names' @tab @var{nm} @tab\n\ @end multitable\n\ \n\ Additional arguments are summarized below.\n\ \n\ @table @samp\n\ @item once\n\ Return only the first occurrence of the pattern.\n\ \n\ @item matchcase\n\ Make the matching case sensitive. (default)\n\ \n\ Alternatively, use (?-i) in the pattern when PCRE is available.\n\ \n\ @item ignorecase\n\ Ignore case when matching the pattern to the string.\n\ \n\ Alternatively, use (?i) in the pattern when PCRE is available.\n\ \n\ @item stringanchors\n\ Match the anchor characters at the beginning and end of the string. \n\ (default)\n\ \n\ Alternatively, use (?-m) in the pattern when PCRE is available.\n\ \n\ @item lineanchors\n\ Match the anchor characters at the beginning and end of the line.\n\ Only available when Octave is compiled with PCRE.\n\ \n\ Alternatively, use (?m) in the pattern when PCRE is available.\n\ \n\ @item dotall\n\ The pattern @code{.} matches all characters including the newline character.\n\ (default)\n\ \n\ Alternatively, use (?s) in the pattern when PCRE is available.\n\ \n\ @item dotexceptnewline\n\ The pattern @code{.} matches all characters except the newline character.\n\ Only available when Octave is compiled with PCRE.\n\ \n\ Alternatively, use (?-s) in the pattern when PCRE is available.\n\ \n\ @item literalspacing\n\ All characters in the pattern, including whitespace, are significant and are\n\ used in pattern matching. (default)\n\ \n\ Alternatively, use (?-x) in the pattern when PCRE is available.\n\ \n\ @item freespacing\n\ The pattern may include arbitrary whitespace and also comments beginning with\n\ the character @samp{#}.\n\ Only available when Octave is compiled with PCRE.\n\ \n\ Alternatively, use (?x) in the pattern when PCRE is available.\n\ \n\ @end table\n\ @seealso{regexpi, strfind, regexprep}\n\ @end deftypefn")
 DEFUN_DLD (regexpi, args, nargout,"-*- texinfo -*-\n\ @deftypefn {Loadable Function} {[@var{s}, @var{e}, @var{te}, @var{m}, @var{t}, @var{nm}] =} regexpi (@var{str}, @var{pat})\n\ @deftypefnx {Loadable Function} {[@dots{}] =} regexpi (@var{str}, @var{pat}, \"@var{opt1}\", @dots{})\n\ \n\ Case insensitive regular expression string matching. Search for @var{pat} in\n\ @var{str} and return the positions and substrings of any matches, or empty\n\ values if there are none. @xref{doc-regexp,,regexp}, for details on the\n\ syntax of the search pattern.\n\ @seealso{regexp}\n\ @end deftypefn")
 DEFUN_DLD (regexprep, args,,"-*- texinfo -*-\n\ @deftypefn {Loadable Function} {@var{outstr} =} regexprep (@var{string}, @var{pat}, @var{repstr})\n\ @deftypefnx {Loadable Function} {@var{outstr} =} regexprep (@var{string}, @var{pat}, @var{repstr}, \"@var{opt1}\", @dots{})\n\ Replace occurrences of pattern @var{pat} in @var{string} with @var{repstr}.\n\ \n\ The pattern is a regular expression as documented for @code{regexp}.\n\ @xref{doc-regexp,,regexp}.\n\ \n\ The replacement string may contain @code{$i}, which substitutes\n\ for the ith set of parentheses in the match string. For example,\n\ \n\ @example\n\ regexprep(\"Bill Dunn\",'(\\w+) (\\w+)','$2, $1')\n\ @end example\n\ \n\ @noindent\n\ returns \"Dunn, Bill\"\n\ \n\ Options in addition to those of @code{regexp} are\n\ \n\ @table @samp\n\ \n\ @item once\n\ Replace only the first occurrence of @var{pat} in the result.\n\ \n\ @item warnings\n\ This option is present for compatibility but is ignored.\n\ \n\ @end table\n\ @seealso{regexp, regexpi, strrep}\n\ @end deftypefn")

Define Documentation

#define MAXLOOKBEHIND   10
#define PCRE_MATCHLIMIT_MAX   10

Typedef Documentation


Function Documentation

DEFUN_DLD ( regexp  ,
args  ,
nargout   
)
DEFUN_DLD ( regexpi  ,
args  ,
nargout   
)
DEFUN_DLD ( regexprep  ,
args   
)
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines