Functions

regexp.cc File Reference

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

Go to the source code of this file.

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.\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\ Escape sequences defined below can also be used inside list\n\ operators. For example, a template for a floating point number might be\n\ @code{[-+.\\d]+}.\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\ @item \\D\n\ Match any non-digit\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{})}.\n\ \n\ @item sp\n\ A cell array of the text not returned by match.\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\ @item @tab 'split' @tab @var{sp} @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.\n\ \n\ @item ignorecase\n\ Ignore case when matching the pattern to the string.\n\ \n\ Alternatively, use (?i) in the pattern.\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.\n\ \n\ @item lineanchors\n\ Match the anchor characters at the beginning and end of the line.\n\ \n\ Alternatively, use (?m) in the pattern.\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.\n\ \n\ @item dotexceptnewline\n\ The pattern @code{.} matches all characters except the newline character.\n\ \n\ Alternatively, use (?-s) in the pattern.\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.\n\ \n\ @item freespacing\n\ The pattern may include arbitrary whitespace and also comments beginning with\n\ the character @samp{#}.\n\ \n\ Alternatively, use (?x) in the pattern.\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")
static octave_value_list octcellregexp (const octave_value_list &args, int nargout, const std::string &who, bool case_insensitive=false)
static octave_value_list octregexp (const octave_value_list &args, int nargout, const std::string &who, bool case_insensitive=false)
static octave_value octregexprep (const octave_value_list &args, const std::string &who)
static void parse_options (regexp::opts &options, const octave_value_list &args, const std::string &who, int skip, bool &extra_args)

Function Documentation

DEFUN_DLD ( regexp  ,
args  ,
nargout   
)

Definition at line 443 of file regexp.cc.

References octcellregexp(), octregexp(), and print_usage().

DEFUN_DLD ( regexpi  ,
args  ,
nargout   
)

Definition at line 872 of file regexp.cc.

References octcellregexp(), octregexp(), and print_usage().

DEFUN_DLD ( regexprep  ,
args   
)
static octave_value_list octcellregexp ( const octave_value_list args,
int  nargout,
const std::string &  who,
bool  case_insensitive = false 
) [static]
static octave_value_list octregexp ( const octave_value_list args,
int  nargout,
const std::string &  who,
bool  case_insensitive = false 
) [static]
static octave_value octregexprep ( const octave_value_list args,
const std::string &  who 
) [static]
static void parse_options ( regexp::opts options,
const octave_value_list args,
const std::string &  who,
int  skip,
bool extra_args 
) [static]
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines