From 7079ba042471d1c78d07373d5ed06c9526dd0b83 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Wed, 25 Jul 2001 10:20:47 +0000 Subject: [PATCH] tweeked docs - added credits + iterator categories. [SVN r10701] --- appendix.htm | 2526 +++++++++++++++++++++------------------- template_class_ref.htm | 1392 ++++++++++------------ 2 files changed, 1973 insertions(+), 1945 deletions(-) diff --git a/appendix.htm b/appendix.htm index 50ec275e..1fdd7822 100644 --- a/appendix.htm +++ b/appendix.htm @@ -1,20 +1,28 @@ - - - - -Regex++, Appendices - - - + -

 

- - - + +
-

C++ Boost

-

Regex++, Appendices.

-

(version 3.12, 18 April 2000)

-
Copyright (c) 1998-2000
+
+
+
+
+Regex++, Appendices
+
+
+
+
+

 

+ + + + + - -

C++ Boost

+

Regex++, + Appendices.

+

(version 3.12, 18 April 2000)

+
Copyright (c) 1998-2000
 Dr John Maddock
 
 Permission to use, copy, modify, distribute and sell this software
@@ -23,1191 +31,1317 @@ provided that the above copyright notice appear in all copies and
 that both that copyright notice and this permission notice appear
 in supporting documentation.  Dr John Maddock makes no representations
 about the suitability of this software for any purpose.  
-It is provided "as is" without express or implied warranty.
+It is provided "as is" without express or implied warranty.
+
-


-

Appendix 1: Implementation notes

-

This is the first port of regex++ to the boost library, and is based on regex++ 2.x, see changes.txt for a full list of changes from the previous version. There are no known functionality bugs except that POSIX style equivalence classes are only guaranteed correct if the Win32 localization model is used (the default for Win32 builds of the library).

-

There are some aspects of the code that C++ puritans will consider to be poor style, in particular the use of goto in some of the algorithms. The code could be cleaned up, by changing to a recursive implementation, although it is likely to be slower in that case.

-

The performance of the algorithms should be satisfactory in most cases. For example the times taken to match the ftp response expression "^([0-9]+)(\-| |$)(.*)$" against the string "100- this is a line of ftp response which contains a message string" are: BSD implementation 450 micro seconds, GNU implementation 271 micro seconds, regex++ 127 micro seconds (Pentium P90, Win32 console app under MS Windows 95).

-

However it should be noted that there are some "pathological" expressions which may require exponential time for matching; these all involve nested repetition operators, for example attempting to match the expression "(a*a)*b" against N letter a's requires time proportional to 2N. These expressions can (almost) always be rewritten in such a way as to avoid the problem, for example "(a*a)*b" could be rewritten as "a*b" which requires only time linearly proportional to N to solve. In the general case, non-nested repeat expressions require time proportional to N2, however if the clauses are mutually exclusive then they can be matched in linear time - this is the case with "a*b", for each character the matcher will either match an "a" or a "b" or fail, where as with "a*a" the matcher can't tell which branch to take (the first "a" or the second) and so has to try both. Be careful how you write your regular expressions and avoid nested repeats if you can! New to this version, some previously pathological cases have been fixed - in particular searching for expressions which contain leading repeats and/or leading literal strings should be much faster than before. Literal strings are now searched for using the Knuth/Morris/Pratt algorithm (this is used in preference to the Boyer/More algorithm because it allows the tracking of newline characters).

-

Some aspects of the POSIX regular expression syntax are implementation defined:

+
- +

Appendix 1: Implementation notes

-


-

Appendix 2: Thread safety

-

Class reg_expression<> and its typedefs regex and wregex are thread safe, in that compiled regular expressions can safely be shared between threads. The matching algorithms regex_match, regex_search, regex_grep, regex_format and regex_merge are all re-entrant and thread safe. Class match_results is now thread safe, in that the results of a match can be safely copied from one thread to another (for example one thread may find matches and push match_results instances onto a queue, while another thread pops them off the other end), otherwise use a separate instance of match_results per thread.

-

The POSIX API functions are all re-entrant and thread safe, regular expressions compiled with regcomp can also be shared between threads.

-

The class RegEx is only thread safe if each thread gets its own RegEx instance (apartment threading) - this is a consequence of RegEx handling both compiling and matching regular expressions.

-

Finally note that changing the global locale invalidates all compiled regular expressions, therefore calling set_locale from one thread while another uses regular expressions will produce unpredictable results.

-

There is also a requirement that there is only one thread executing prior to the start of main().

-


-

Appendix 3: Localization

-

 Regex++ provides extensive support for run-time localization, the localization model used can be split into two parts: front-end and back-end.

-

Front-end localization deals with everything which the user sees - error messages, and the regular expression syntax itself. For example a French application could change [[:word:]] to [[:mot:]] and \w to \m. Modifying the front end locale requires active support from the developer, by providing the library with a message catalogue to load, containing the localized strings. Front-end locale is affected by the LC_MESSAGES category only.

-

Back-end localization deals with everything that occurs after the expression has been parsed - in other words everything that the user does not see or interact with directly. It deals with case conversion, collation, and character class membership. The back-end locale does not require any intervention from the developer - the library will acquire all the information it requires for the current locale from the underlying operating system / run time library. This means that if the program user does not interact with regular expressions directly - for example if the expressions are embedded in your C++ code - then no explicit localization is required, as the library will take care of everything for you. For example embedding the expression [[:word:]]+ in your code will always match a whole word, if the program is run on a machine with, for example, a Greek locale, then it will still match a whole word, but in Greek characters rather than Latin ones. The back-end locale is affected by the LC_TYPE and LC_COLLATE categories.

-

There are three separate localization mechanisms supported by regex++:

-

Win32 localization model.

-

This is the default model when the library is compiled under Win32, and is encapsulated by the traits class w32_regex_traits. When this model is in effect there is a single global locale as defined by the user's control panel settings, and returned by GetUserDefaultLCID. All the settings used by regex++ are acquired directly from the operating system bypassing the C run time library. Front-end localization requires a resource dll, containing a string table with the user-defined strings. The traits class exports the function:

-

static std::string set_message_catalogue(const std::string& s);

-

which needs to be called with a string identifying the name of the resource dll, before your code compiles any regular expressions (but not necessarily before you construct any reg_expression instances):

-

boost::w32_regex_traits<char>::set_message_calalogue("mydll.dll");

-

Note that this API sets the dll name for both the narrow and wide character specializations of w32_regex_traits.

-

This model does not currently support thread specific locales (via SetThreadLocale under Windows NT), the library provides full Unicode support under NT, under Windows 9x the library degrades gracefully - characters 0 to 255 are supported, the remainder are treated as "unknown" graphic characters.

-

C localization model.

-

This is the default model when the library is compiled under an operating system other than Win32, and is encapsulated by the traits class c_regex_traits, Win32 users can force this model to take effect by defining the pre-processor symbol BOOST_RE_LOCALE_C. When this model is in effect there is a single global locale, as set by setlocale. All settings are acquired from your run time library, consequently Unicode support is dependent upon your run time library implementation. Front end localization requires a POSIX message catalogue. The traits class exports the function:

-

static std::string set_message_catalogue(const std::string& s);

-

which needs to be called with a string identifying the name of the message catalogue, before your code compiles any regular expressions (but not necessarily before you construct any reg_expression instances):

-

boost::c_regex_traits<char>::set_message_calalogue("mycatalogue");

-

Note that this API sets the dll name for both the narrow and wide character specializations of c_regex_traits. If your run time library does not support POSIX message catalogues, then you can either provide your own implementation of <nl_types.h> or define BOOST_RE_NO_CAT to disable front-end localization via message catalogues.

-

Note that calling setlocale invalidates all compiled regular expressions, calling setlocale(LC_ALL, "C") will make this library behave equivalent to most traditional regular expression libraries including version 1 of this library.

-

C++ localization model.

-

This model is only in effect if the library is built with the pre-processor symbol BOOST_RE_LOCALE_CPP defined. When this model is in effect each instance of reg_expression<> has its own instance of std::locale, class reg_expression<> also has a member function imbue which allows the locale for the expression to be set on a per-instance basis. Front end localization requires a POSIX message catalogue, which will be loaded via the std::messages facet of the expression's locale, the traits class exports the symbol:

-

static std::string set_message_catalogue(const std::string& s);

-

which needs to be called with a string identifying the name of the message catalogue, before your code compiles any regular expressions (but not necessarily before you construct any reg_expression instances):

-

boost::cpp_regex_traits<char>::set_message_calalogue("mycatalogue");

-

Note that calling reg_expression<>::imbue will invalidate any expression currently compiled in that instance of reg_expression<>. This model is the one which closest fits the ethos of the C++ standard library, however it is the model which will produce the slowest code, and which is the least well supported by current standard library implementations, for example I have yet to find an implementation of std::locale which supports either message catalogues, or locales other than "C" or "POSIX".

-

Finally note that if you build the library with a non-default localization model, then the appropriate pre-processor symbol (BOOST_RE_LOCALE_C or BOOST_RE_LOCALE_CPP) must be defined both when you build the support library, and when you include <boost/regex.hpp> or <boost/cregex.hpp> in your code. The best way to ensure this is to add the #define to <boost/regex/detail/regex_options.hpp>.

-

Providing a message catalogue:

-

In order to localize the front end of the library, you need to provide the library with the appropriate message strings contained either in a resource dll's string table (Win32 model), or a POSIX message catalogue (C or C++ models). In the latter case the messages must appear in message set zero of the catalogue. The messages and their id's are as follows:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-

 

-

Message id

-

Meaning

-

Default value

-

 

-

 

-

101

-

The character used to start a sub-expression.

-

"("

-

 

-

 

-

102

-

The character used to end a sub-expression declaration.

-

")"

-

 

-

 

-

103

-

The character used to denote an end of line assertion.

-

"$"

-

 

-

 

-

104

-

The character used to denote the start of line assertion.

-

"^"

-

 

-

 

-

105

-

The character used to denote the "match any character expression".

-

"."

-

 

-

 

-

106

-

The match zero or more times repetition operator.

-

"*"

-

 

-

 

-

107

-

The match one or more repetition operator.

-

"+"

-

 

-

 

-

108

-

The match zero or one repetition operator.

-

"?"

-

 

-

 

-

109

-

The character set opening character.

-

"["

-

 

-

 

-

110

-

The character set closing character.

-

"]"

-

 

-

 

-

111

-

The alternation operator.

-

"|"

-

 

-

 

-

112

-

The escape character.

-

"\\"

-

 

-

 

-

113

-

The hash character (not currently used).

-

"#"

-

 

-

 

-

114

-

The range operator.

-

"-"

-

 

-

 

-

115

-

The repetition operator opening character.

-

"{"

-

 

-

 

-

116

-

The repetition operator closing character.

-

"}"

-

 

-

 

-

117

-

The digit characters.

-

"0123456789"

-

 

-

 

-

118

-

The character which when preceded by an escape character represents the word boundary assertion.

-

"b"

-

 

-

 

-

119

-

The character which when preceded by an escape character represents the non-word boundary assertion.

-

"B"

-

 

-

 

-

120

-

The character which when preceded by an escape character represents the word-start boundary assertion.

-

"<"

-

 

-

 

-

121

-

The character which when preceded by an escape character represents the word-end boundary assertion.

-

">"

-

 

-

 

-

122

-

The character which when preceded by an escape character represents any word character.

-

"w"

-

 

-

 

-

123

-

The character which when preceded by an escape character represents a non-word character.

-

"W"

-

 

-

 

-

124

-

The character which when preceded by an escape character represents a start of buffer assertion.

-

"`A"

-

 

-

 

-

125

-

The character which when preceded by an escape character represents an end of buffer assertion.

-

"'z"

-

 

-

 

-

126

-

The newline character.

-

"\n"

-

 

-

 

-

127

-

The comma separator.

-

","

-

 

-

 

-

128

-

The character which when preceded by an escape character represents the bell character.

-

"a"

-

 

-

 

-

129

-

The character which when preceded by an escape character represents the form feed character.

-

"f"

-

 

-

 

-

130

-

The character which when preceded by an escape character represents the newline character.

-

"n"

-

 

-

 

-

131

-

The character which when preceded by an escape character represents the carriage return character.

-

"r"

-

 

-

 

-

132

-

The character which when preceded by an escape character represents the tab character.

-

"t"

-

 

-

 

-

133

-

The character which when preceded by an escape character represents the vertical tab character.

-

"v"

-

 

-

 

-

134

-

The character which when preceded by an escape character represents the start of a hexadecimal character constant.

-

"x"

-

 

-

 

-

135

-

The character which when preceded by an escape character represents the start of an ASCII escape character.

-

"c"

-

 

-

 

-

136

-

The colon character.

-

":"

-

 

-

 

-

137

-

The equals character.

-

"="

-

 

-

 

-

138

-

The character which when preceded by an escape character represents the ASCII escape character.

-

"e"

-

 

-

 

-

139

-

The character which when preceded by an escape character represents any lower case character.

-

"l"

-

 

-

 

-

140

-

The character which when preceded by an escape character represents any non-lower case character.

-

"L"

-

 

-

 

-

141

-

The character which when preceded by an escape character represents any upper case character.

-

"u"

-

 

-

 

-

142

-

The character which when preceded by an escape character represents any non-upper case character.

-

"U"

-

 

-

 

-

143

-

The character which when preceded by an escape character represents any space character.

-

"s"

-

 

-

 

-

144

-

The character which when preceded by an escape character represents any non-space character.

-

"S"

-

 

-

 

-

145

-

The character which when preceded by an escape character represents any digit character.

-

"d"

-

 

-

 

-

146

-

The character which when preceded by an escape character represents any non-digit character.

-

"D"

-

 

-

 

-

147

-

The character which when preceded by an escape character represents the end quote operator.

-

"E"

-

 

-

 

-

148

-

The character which when preceded by an escape character represents the start quote operator.

-

"Q"

-

 

-

 

-

149

-

The character which when preceded by an escape character represents a Unicode combining character sequence.

-

"X"

-

 

-

 

-

150

-

The character which when preceded by an escape character represents any single character.

-

"C"

-

 

-

 

-

151

-

The character which when preceded by an escape character represents end of buffer operator.

-

"Z"

-

 

-

 

-

152

-

The character which when preceded by an escape character represents the continuation assertion.

-

"G"

-

 

+

This is the first port of regex++ to the boost library, and is +based on regex++ 2.x, see changes.txt for a full list of changes +from the previous version. There are no known functionality bugs +except that POSIX style equivalence classes are only guaranteed +correct if the Win32 localization model is used (the default for +Win32 builds of the library).

-


-

Custom error messages are loaded as follows:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-

 

-

Message ID

-

Error message ID

-

Default string

-

 

-

 

-

201

-

REG_NOMATCH

-

"No match"

-

 

-

 

-

202

-

REG_BADPAT

-

"Invalid regular expression"

-

 

-

 

-

203

-

REG_ECOLLATE

-

"Invalid collation character"

-

 

-

 

-

204

-

REG_ECTYPE

-

"Invalid character class name"

-

 

-

 

-

205

-

REG_EESCAPE

-

"Trailing backslash"

-

 

-

 

-

206

-

REG_ESUBREG

-

"Invalid back reference"

-

 

-

 

-

207

-

REG_EBRACK

-

"Unmatched [ or [^"

-

 

-

 

-

208

-

REG_EPAREN

-

"Unmatched ( or \\("

-

 

-

 

-

209

-

REG_EBRACE

-

"Unmatched \\{"

-

 

-

 

-

210

-

REG_BADBR

-

"Invalid content of \\{\\}"

-

 

-

 

-

211

-

REG_ERANGE

-

"Invalid range end"

-

 

-

 

-

212

-

REG_ESPACE

-

"Memory exhausted"

-

 

-

 

-

213

-

REG_BADRPT

-

"Invalid preceding regular expression"

-

 

-

 

-

214

-

REG_EEND

-

"Premature end of regular expression"

-

 

-

 

-

215

-

REG_ESIZE

-

"Regular expression too big"

-

 

-

 

-

216

-

REG_ERPAREN

-

"Unmatched ) or \\)"

-

 

-

 

-

217

-

REG_EMPTY

-

"Empty expression"

-

 

-

 

-

218

-

REG_E_UNKNOWN

-

"Unknown error"

-

 

+

There are some aspects of the code that C++ puritans will +consider to be poor style, in particular the use of goto in some +of the algorithms. The code could be cleaned up, by changing to a +recursive implementation, although it is likely to be slower in +that case.

-


-

Custom character class names are loaded as followed:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-

 

-

Message ID

-

Description

-

Equivalent default class name

-

 

-

 

-

300

-

The character class name for alphanumeric characters.

-

"alnum"

-

 

-

 

-

301

-

The character class name for alphabetic characters.

-

"alpha"

-

 

-

 

-

302

-

The character class name for control characters.

-

"cntrl"

-

 

-

 

-

303

-

The character class name for digit characters.

-

"digit"

-

 

-

 

-

304

-

The character class name for graphics characters.

-

"graph"

-

 

-

 

-

305

-

The character class name for lower case characters.

-

"lower"

-

 

-

 

-

306

-

The character class name for printable characters.

-

"print"

-

 

-

 

-

307

-

The character class name for punctuation characters.

-

"punct"

-

 

-

 

-

308

-

The character class name for space characters.

-

"space"

-

 

-

 

-

309

-

The character class name for upper case characters.

-

"upper"

-

 

-

 

-

310

-

The character class name for hexadecimal characters.

-

"xdigit"

-

 

-

 

-

311

-

The character class name for blank characters.

-

"blank"

-

 

-

 

-

312

-

The character class name for word characters.

-

"word"

-

 

-

 

-

313

-

The character class name for Unicode characters.

-

"unicode"

-

 

+

The performance of the algorithms should be satisfactory in +most cases. For example the times taken to match the ftp response +expression "^([0-9]+)(\-| |$)(.*)$" against the string +"100- this is a line of ftp response which contains a +message string" are: BSD implementation 450 micro seconds, +GNU implementation 271 micro seconds, regex++ 127 micro seconds (Pentium +P90, Win32 console app under MS Windows 95).

-


-

Finally, custom collating element names are loaded starting from message id 400, and terminating when the first load thereafter fails. Each message looks something like: "tagname string" where tagname is the name used inside [[.tagname.]] and string is the actual text of the collating element. Note that the value of collating element [[.zero.]] is used for the conversion of strings to numbers - if you replace this with another value then that will be used for string parsing - for example use the Unicode character 0x0660 for [[.zero.]] if you want to use Unicode Arabic-Indic digits in your regular expressions in place of Latin digits.

-

Note that the POSIX defined names for character classes and collating elements are always available - even if custom names are defined, in contrast, custom error messages, and custom syntax messages replace the default ones.

-


-

Appendix 4: Example Applications

-

There are three demo applications that ship with this library, they all come with makefiles for Borland, Microsoft and gcc compilers, otherwise you will have to create your own makefiles.

-
regress.exe:
-

A regression test application that gives the matching/searching algorithms a full workout. The presence of this program is your guarantee that the library will behave as claimed - at least as far as those items tested are concerned - if anyone spots anything that isn't being tested I'd be glad to hear about it.

-

Files: parse.cpp, regress.cpp, tests.cpp.

-
jgrep.exe
-

A simple grep implementation, run with no command line options to find out its usage. Look at fileiter.cpp/fileiter.hpp and the mapfile class to see an example of a "smart" bidirectional iterator that can be used with regex++ or any other STL algorithm.

-

Files: jgrep.cpp, main.cpp.

-
timer.exe
-

A simple interactive expression matching application, the results of all matches are timed, allowing the programmer to optimize their regular expressions where performance is critical.

-

Files: regex_timer.cpp.

-

The snippets examples contain the code examples used in the documentation:

-

regex_match_example.cpp: ftp based regex_match example.

-

regex_search_example.cpp: regex_search example: searches a cpp file for class definitions.

-

regex_grep_example_1.cpp: regex_grep example 1: searches a cpp file for class definitions.

-

regex_merge_example.cpp: regex_merge example: converts a C++ file to syntax highlighted HTML.

-

regex_grep_example_2.cpp: regex_grep example 2: searches a cpp file for class definitions, using a global callback function.

-

regex_grep_example_3.cpp: regex_grep example 2: searches a cpp file for class definitions, using a bound member function callback.

-

regex_grep_example_4.cpp: regex_grep example 2: searches a cpp file for class definitions, using a C++ Builder closure as a callback.

-

regex_split_example_1.cpp: regex_split example: split a string into tokens.

-

regex_split_example_2.cpp: regex_split example: spit out linked URL's.

-


-

Appendix 5: Header Files

-

There are two main headers used by this library: <boost/regex.hpp> provides full access to the entire library, while <boost/cregex.hpp> provides access to just the high level class RegEx, and the POSIX API functions.

-


-

Appendix 6: Redistributables

-

 If you are using Microsoft or Borland C++ and link to a dll version of the run time library, then you will also link to one of the dll versions of regex++. While these dll's are redistributable, there are no "standard" versions, so when installing on the users PC, you should place these in a directory private to your application, and not in the PC's directory path. Note that if you link to a static version of your run time library, then you will also link to a static version of regex++ and no dll's will need to be distributed. The possible regex++ dll's are as follows:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-

 

-

Development Tool

-

Run Time Library

-

Regex++ Dll

-

 

-

 

-

Microsoft Visual C++ 6

-

Msvcp60.dll and msvcrt.dll

-

Mre200l.dll

-

 

-

 

-

Microsoft Visual C++ 6

-

Msvcp60d.dll and msvcrtd.dll

-

Mre300dl.dll

-

 

-

 

-

Borland C++ Builder 4

-

Cw3245.dll

-

bcb4re300l.dll

-

 

-

 

-

Borland C++ Builder 4

-

Cw3245mt.dll

-

bcb4re300lm.dll

-

 

-

 

-

Borland C++ Builder 4

-

Cp3245mt.dll and vcl40.bpl

-

bcb4re300lv.dll

-

 

-

 

-

Borland C++ Builder 5

-

cp3250.dll

-

bcb5re300l.dll

-

 

-

 

-

Borland C++ Builder 5

-

cp3250mt.dll

-

bcb5re300lm.dll

-

 

-

 

-

Borland C++ Builder 5

-

cw3250mt.dll

-

bcb5re300lv.dll

-

 

+

However it should be noted that there are some "pathological" +expressions which may require exponential time for matching; +these all involve nested repetition operators, for example +attempting to match the expression "(a*a)*b" against N +letter a's requires time proportional to 2N. +These expressions can (almost) always be rewritten in such a way +as to avoid the problem, for example "(a*a)*b" could be +rewritten as "a*b" which requires only time linearly +proportional to N to solve. In the general case, non-nested +repeat expressions require time proportional to N2, +however if the clauses are mutually exclusive then they can be +matched in linear time - this is the case with "a*b", +for each character the matcher will either match an "a" +or a "b" or fail, where as with "a*a" the +matcher can't tell which branch to take (the first "a" +or the second) and so has to try both. Be careful how you +write your regular expressions and avoid nested repeats if you +can! New to this version, some previously pathological cases have +been fixed - in particular searching for expressions which +contain leading repeats and/or leading literal strings should be +much faster than before. Literal strings are now searched for +using the Knuth/Morris/Pratt algorithm (this is used in +preference to the Boyer/More algorithm because it allows the +tracking of newline characters).

-

Note: you can disable automatic library selection by defining the symbol BOOST_RE_NO_LIB when compiling, this is useful if you want to statically link even though you're using the dll version of your run time library, or if you need to debug regex++.

-


-

Notes for upgraders

-

This version of regex++ is the first to be ported to the boost project, and as a result has a number of changes to comply with the boost coding guidelines.

-

Headers have been changed from <header> or <header.h> to <boost/header.hpp>

-

The library namespace has changed from "jm", to "boost".

-

The reg_xxx algorithms have been renamed regex_xxx (to improve naming consistency).

-

Algorithm query_match has been renamed regex_match, and only returns true if the expression matches the whole of the input string (think input data validation).

-

Compiling existing code:

-

The directory, libs/regex/old_include contains a set of headers that make this version of regex++ compatible with previous ones, either add this directory to your include path, or copy these headers to the root directory of your boost installation. The contents of these headers are deprecated and undocumented - really these are just here for existing code - for new projects use the new header forms.

-


-

Further Information (Contacts and Acknowledgements)

-

The author can be contacted at John_Maddock@compuserve.com, the home page for this library is at http://ourworld.compuserve.com/homepages/John_Maddock/regexpp.htm, and the official boost version can be obtained from www.boost.org/libraries.htm.

-

I am indebted to Robert Sedgewick's "Algorithms in C++" for forcing me to think about algorithms and their performance, and to the folks at boost for forcing me to think, period. The following people have all contributed useful comments or fixes: Dave Abrahams, Mike Allison, Edan Ayal, Jayashree Balasubramanian, Beman Dawes, Paul Baxter, David Dennerline, Edward Diener, Robert Dunn, , Fabio Forno, Tobias Gabrielsson, Rob Gillen, Marc Gregoire, Chris Hecker, Nick Hodapp, Jesse Jones, Martin Jost, Boris Krasnovskiy, Jan Hermelink, Max Leung, Wei-hao Lin, Jens Maurer, Heiko Schmidt, Scobie Smith, Alexander Sokolovsky, Hervé Poirier, Marc Recht, Bruno Voigt, Alexey Voinov, Jerry Waldorf, Rob Ward, Lealon Watts, Thomas Witt and Yuval Yosef. I am also grateful to the manuals supplied with the Henry Spencer, Perl and GNU regular expression libraries - wherever possible I have tried to maintain compatibility with these libraries and with the POSIX standard - the code however is entirely my own, including any bugs! I can absolutely guarantee that I will not fix any bugs I don't know about, so if you have any comments or spot any bugs, please get in touch.

-

Useful further information can be found at:

-

A short tutorial on regular expressions can be found here.

-

The Open Unix Specification contains a wealth of useful material, including the regular expression syntax, and specifications for <regex.h> and <nl_types.h>.

-

The Pattern Matching Pointers site is a "must visit" resource for anyone interested in pattern matching.

-

Glimpse and Agrep, use a simplified regular expression syntax to achieve faster search times.

-

Udi Manber and Ricardo Baeza-Yates both have a selection of useful pattern matching papers available from their respective web sites.

-


-

Copyright Dr John Maddock 1998-2000 all rights reserved.

- +

Some aspects of the POSIX regular expression syntax are +implementation defined:

+ + +
+ +

Appendix 2: Thread safety

+ +

Class reg_expression<> and its typedefs regex and wregex +are thread safe, in that compiled regular expressions can safely +be shared between threads. The matching algorithms regex_match, +regex_search, regex_grep, regex_format and regex_merge are all re-entrant +and thread safe. Class match_results is now thread safe, in that +the results of a match can be safely copied from one thread to +another (for example one thread may find matches and push +match_results instances onto a queue, while another thread pops +them off the other end), otherwise use a separate instance of +match_results per thread.

+ +

The POSIX API functions are all re-entrant and thread safe, +regular expressions compiled with regcomp can also be +shared between threads.

+ +

The class RegEx is only thread safe if each thread gets its +own RegEx instance (apartment threading) - this is a consequence +of RegEx handling both compiling and matching regular expressions. +

+ +

Finally note that changing the global locale invalidates all +compiled regular expressions, therefore calling set_locale +from one thread while another uses regular expressions will +produce unpredictable results.

+ +

There is also a requirement that there is only one thread +executing prior to the start of main().

+ +
+ +

Appendix 3: Localization

+ +

 Regex++ provides extensive support for run-time +localization, the localization model used can be split into two +parts: front-end and back-end.

+ +

Front-end localization deals with everything which the user +sees - error messages, and the regular expression syntax itself. +For example a French application could change [[:word:]] to [[:mot:]] +and \w to \m. Modifying the front end locale requires active +support from the developer, by providing the library with a +message catalogue to load, containing the localized strings. +Front-end locale is affected by the LC_MESSAGES category only.

+ +

Back-end localization deals with everything that occurs after +the expression has been parsed - in other words everything that +the user does not see or interact with directly. It deals with +case conversion, collation, and character class membership. The +back-end locale does not require any intervention from the +developer - the library will acquire all the information it +requires for the current locale from the underlying operating +system / run time library. This means that if the program user +does not interact with regular expressions directly - for example +if the expressions are embedded in your C++ code - then no +explicit localization is required, as the library will take care +of everything for you. For example embedding the expression [[:word:]]+ +in your code will always match a whole word, if the program is +run on a machine with, for example, a Greek locale, then it will +still match a whole word, but in Greek characters rather than +Latin ones. The back-end locale is affected by the LC_TYPE and +LC_COLLATE categories.

+ +

There are three separate localization mechanisms supported by +regex++:

+ +

Win32 localization model.

+ +

This is the default model when the library is compiled under +Win32, and is encapsulated by the traits class w32_regex_traits. +When this model is in effect there is a single global locale as +defined by the user's control panel settings, and returned by +GetUserDefaultLCID. All the settings used by regex++ are acquired +directly from the operating system bypassing the C run time +library. Front-end localization requires a resource dll, +containing a string table with the user-defined strings. The +traits class exports the function:

+ +

static std::string set_message_catalogue(const std::string& +s);

+ +

which needs to be called with a string identifying the name of +the resource dll, before your code compiles any regular +expressions (but not necessarily before you construct any reg_expression +instances):

+ +

boost::w32_regex_traits<char>::set_message_calalogue("mydll.dll"); +

+ +

Note that this API sets the dll name for both the +narrow and wide character specializations of w32_regex_traits.

+ +

This model does not currently support thread specific locales +(via SetThreadLocale under Windows NT), the library provides full +Unicode support under NT, under Windows 9x the library degrades +gracefully - characters 0 to 255 are supported, the remainder are +treated as "unknown" graphic characters.

+ +

C localization model.

+ +

This is the default model when the library is compiled under +an operating system other than Win32, and is encapsulated by the +traits class c_regex_traits, +Win32 users can force this model to take effect by defining the +pre-processor symbol BOOST_RE_LOCALE_C. When this model is in +effect there is a single global locale, as set by setlocale. +All settings are acquired from your run time library, +consequently Unicode support is dependent upon your run time +library implementation. Front end localization requires a POSIX +message catalogue. The traits class exports the function:

+ +

static std::string set_message_catalogue(const std::string& +s);

+ +

which needs to be called with a string identifying the name of +the message catalogue, before your code compiles any +regular expressions (but not necessarily before you construct any +reg_expression instances):

+ +

boost::c_regex_traits<char>::set_message_calalogue("mycatalogue"); +

+ +

Note that this API sets the dll name for both the +narrow and wide character specializations of c_regex_traits. If +your run time library does not support POSIX message catalogues, +then you can either provide your own implementation of +<nl_types.h> or define BOOST_RE_NO_CAT to disable front-end +localization via message catalogues.

+ +

Note that calling setlocale invalidates all compiled +regular expressions, calling setlocale(LC_ALL, "C") +will make this library behave equivalent to most traditional +regular expression libraries including version 1 of this library. +

+ +

C++ localization model. +

+ +

This model is only in effect if the library is built with the +pre-processor symbol BOOST_RE_LOCALE_CPP defined. When this model +is in effect each instance of reg_expression<> has its own +instance of std::locale, class reg_expression<> also has a +member function imbue which allows the locale for the +expression to be set on a per-instance basis. Front end +localization requires a POSIX message catalogue, which will be +loaded via the std::messages facet of the expression's locale, +the traits class exports the symbol:

+ +

static std::string set_message_catalogue(const std::string& +s);

+ +

which needs to be called with a string identifying the name of +the message catalogue, before your code compiles any +regular expressions (but not necessarily before you construct any +reg_expression instances):

+ +

boost::cpp_regex_traits<char>::set_message_calalogue("mycatalogue"); +

+ +

Note that calling reg_expression<>::imbue will +invalidate any expression currently compiled in that instance of +reg_expression<>. This model is the one which closest fits +the ethos of the C++ standard library, however it is the model +which will produce the slowest code, and which is the least well +supported by current standard library implementations, for +example I have yet to find an implementation of std::locale which +supports either message catalogues, or locales other than "C" +or "POSIX".

+ +

Finally note that if you build the library with a non-default +localization model, then the appropriate pre-processor symbol (BOOST_RE_LOCALE_C +or BOOST_RE_LOCALE_CPP) must be defined both when you build the +support library, and when you include <boost/regex.hpp> or +<boost/cregex.hpp> in your code. The best way to ensure +this is to add the #define to <boost/regex/detail/regex_options.hpp>. +

+ +

Providing a message catalogue:

+ +

In order to localize the front end of the library, you need to +provide the library with the appropriate message strings +contained either in a resource dll's string table (Win32 model), +or a POSIX message catalogue (C or C++ models). In the latter +case the messages must appear in message set zero of the +catalogue. The messages and their id's are as follows:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
 Message id Meaning Default value  
 101 The character used to start + a sub-expression. "("  
 102 The character used to end a + sub-expression declaration. ")"  
 103 The character used to denote + an end of line assertion. "$"  
 104 The character used to denote + the start of line assertion. "^"  
 105 The character used to denote + the "match any character expression". "."  
 106 The match zero or more times + repetition operator. "*"  
 107 The match one or more + repetition operator. "+"  
 108 The match zero or one + repetition operator. "?"  
 109 The character set opening + character. "["  
 110 The character set closing + character. "]"  
 111 The alternation operator. "|"  
 112 The escape character. "\\"  
 113 The hash character (not + currently used). "#"  
 114 The range operator. "-"  
 115 The repetition operator + opening character. "{"  
 116 The repetition operator + closing character. "}"  
 117 The digit characters. "0123456789"  
 118 The character which when + preceded by an escape character represents the word + boundary assertion. "b"  
 119 The character which when + preceded by an escape character represents the non-word + boundary assertion. "B"  
 120 The character which when + preceded by an escape character represents the word-start + boundary assertion. "<"  
 121 The character which when + preceded by an escape character represents the word-end + boundary assertion. ">"  
 122 The character which when + preceded by an escape character represents any word + character. "w"  
 123 The character which when + preceded by an escape character represents a non-word + character. "W"  
 124 The character which when + preceded by an escape character represents a start of + buffer assertion. "`A"  
 125 The character which when + preceded by an escape character represents an end of + buffer assertion. "'z"  
 126 The newline character. "\n"  
 127 The comma separator. ","  
 128 The character which when + preceded by an escape character represents the bell + character. "a"  
 129 The character which when + preceded by an escape character represents the form feed + character. "f"  
 130 The character which when + preceded by an escape character represents the newline + character. "n"  
 131 The character which when + preceded by an escape character represents the carriage + return character. "r"  
 132 The character which when + preceded by an escape character represents the tab + character. "t"  
 133 The character which when + preceded by an escape character represents the vertical + tab character. "v"  
 134 The character which when + preceded by an escape character represents the start of a + hexadecimal character constant. "x"  
 135 The character which when + preceded by an escape character represents the start of + an ASCII escape character. "c"  
 136 The colon character. ":"  
 137 The equals character. "="  
 138 The character which when + preceded by an escape character represents the ASCII + escape character. "e"  
 139 The character which when + preceded by an escape character represents any lower case + character. "l"  
 140 The character which when + preceded by an escape character represents any non-lower + case character. "L"  
 141 The character which when + preceded by an escape character represents any upper case + character. "u"  
 142 The character which when + preceded by an escape character represents any non-upper + case character. "U"  
 143 The character which when + preceded by an escape character represents any space + character. "s"  
 144 The character which when + preceded by an escape character represents any non-space + character. "S"  
 145 The character which when + preceded by an escape character represents any digit + character. "d"  
 146 The character which when + preceded by an escape character represents any non-digit + character. "D"  
 147 The character which when + preceded by an escape character represents the end quote + operator. "E"  
 148 The character which when + preceded by an escape character represents the start + quote operator. "Q"  
 149 The character which when + preceded by an escape character represents a Unicode + combining character sequence. "X"  
 150 The character which when + preceded by an escape character represents any single + character. "C"  
 151 The character which when + preceded by an escape character represents end of buffer + operator. "Z"  
 152 The character which when + preceded by an escape character represents the + continuation assertion. "G"  
+ +


+ +

Custom error messages are loaded as follows:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
 Message ID Error message ID Default string  
 201 REG_NOMATCH "No match"  
 202 REG_BADPAT "Invalid regular + expression"  
 203 REG_ECOLLATE "Invalid collation + character"  
 204 REG_ECTYPE "Invalid character + class name"  
 205 REG_EESCAPE "Trailing backslash" +  
 206 REG_ESUBREG "Invalid back reference" +  
 207 REG_EBRACK "Unmatched [ or [^" +  
 208 REG_EPAREN "Unmatched ( or \\(" +  
 209 REG_EBRACE "Unmatched \\{"  
 210 REG_BADBR "Invalid content of + \\{\\}"  
 211 REG_ERANGE "Invalid range end" +  
 212 REG_ESPACE "Memory exhausted" +  
 213 REG_BADRPT "Invalid preceding + regular expression"  
 214 REG_EEND "Premature end of + regular expression"  
 215 REG_ESIZE "Regular expression too + big"  
 216 REG_ERPAREN "Unmatched ) or \\)" +  
 217 REG_EMPTY "Empty expression" +  
 218 REG_E_UNKNOWN "Unknown error"  
+ +


+ +

Custom character class names are loaded as followed:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
 Message ID Description Equivalent default class + name  
 300 The character class name for + alphanumeric characters. "alnum"  
 301 The character class name for + alphabetic characters. "alpha"  
 302 The character class name for + control characters. "cntrl"  
 303 The character class name for + digit characters. "digit"  
 304 The character class name for + graphics characters. "graph"  
 305 The character class name for + lower case characters. "lower"  
 306 The character class name for + printable characters. "print"  
 307 The character class name for + punctuation characters. "punct"  
 308 The character class name for + space characters. "space"  
 309 The character class name for + upper case characters. "upper"  
 310 The character class name for + hexadecimal characters. "xdigit"  
 311 The character class name for + blank characters. "blank"  
 312 The character class name for + word characters. "word"  
 313 The character class name for + Unicode characters. "unicode"  
+ +


+ +

Finally, custom collating element names are loaded starting +from message id 400, and terminating when the first load +thereafter fails. Each message looks something like: "tagname +string" where tagname is the name used inside [[.tagname.]] +and string is the actual text of the collating element. +Note that the value of collating element [[.zero.]] is used for +the conversion of strings to numbers - if you replace this with +another value then that will be used for string parsing - for +example use the Unicode character 0x0660 for [[.zero.]] if you +want to use Unicode Arabic-Indic digits in your regular +expressions in place of Latin digits.

+ +

Note that the POSIX defined names for character classes and +collating elements are always available - even if custom names +are defined, in contrast, custom error messages, and custom +syntax messages replace the default ones.

+ +
+ +

Appendix 4: Example Applications

+ +

There are three demo applications that ship with this library, +they all come with makefiles for Borland, Microsoft and gcc +compilers, otherwise you will have to create your own makefiles.

+ +
regress.exe:
+ +

A regression test application that gives the matching/searching +algorithms a full workout. The presence of this program is your +guarantee that the library will behave as claimed - at least as +far as those items tested are concerned - if anyone spots +anything that isn't being tested I'd be glad to hear about it.

+ +

Files: parse.cpp, regress.cpp, tests.cpp.

+ +
jgrep.exe
+ +

A simple grep implementation, run with no command line options +to find out its usage. Look at fileiter.cpp/fileiter.hpp +and the mapfile class to see an example of a "smart" +bidirectional iterator that can be used with regex++ or any other +STL algorithm.

+ +

Files: jgrep.cpp, main.cpp.

+ +
timer.exe
+ +

A simple interactive expression matching application, the +results of all matches are timed, allowing the programmer to +optimize their regular expressions where performance is critical. +

+ +

Files: regex_timer.cpp. +

+ +

The snippets examples contain the code examples used in the +documentation:

+ +

regex_match_example.cpp: +ftp based regex_match example.

+ +

regex_search_example.cpp: +regex_search example: searches a cpp file for class definitions.

+ +

regex_grep_example_1.cpp: +regex_grep example 1: searches a cpp file for class definitions.

+ +

regex_merge_example.cpp: +regex_merge example: converts a C++ file to syntax highlighted +HTML.

+ +

regex_grep_example_2.cpp: +regex_grep example 2: searches a cpp file for class definitions, +using a global callback function.

+ +

regex_grep_example_3.cpp: +regex_grep example 2: searches a cpp file for class definitions, +using a bound member function callback.

+ +

regex_grep_example_4.cpp: +regex_grep example 2: searches a cpp file for class definitions, +using a C++ Builder closure as a callback.

+ +

regex_split_example_1.cpp: +regex_split example: split a string into tokens.

+ +

regex_split_example_2.cpp: +regex_split example: spit out linked URL's.

+ +
+ +

Appendix 5: Header Files

+ +

There are two main headers used by this library: <boost/regex.hpp> +provides full access to the entire library, while <boost/cregex.hpp> +provides access to just the high level class RegEx, and the POSIX +API functions.

+ +
+ +

Appendix 6: Redistributables

+ +

 If you are using Microsoft or Borland C++ and link to a +dll version of the run time library, then you will also link to +one of the dll versions of regex++. While these dll's are +redistributable, there are no "standard" versions, so +when installing on the users PC, you should place these in a +directory private to your application, and not in the PC's +directory path. Note that if you link to a static version of your +run time library, then you will also link to a static version of +regex++ and no dll's will need to be distributed. The possible +regex++ dll's are as follows:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
 Development Tool Run Time Library Regex++ Dll  
 Microsoft Visual C++ 6 Msvcp60.dll and msvcrt.dll Mre200l.dll  
 Microsoft Visual C++ 6 Msvcp60d.dll and msvcrtd.dll + Mre300dl.dll  
 Borland C++ Builder 4 Cw3245.dll bcb4re300l.dll  
 Borland C++ Builder 4 Cw3245mt.dll bcb4re300lm.dll  
 Borland C++ Builder 4 Cp3245mt.dll and vcl40.bpl bcb4re300lv.dll  
 

Borland C++ + Builder 5

+

cp3250.dll

+
bcb5re300l.dll 
 

Borland C++ + Builder 5

+

cp3250mt.dll

+
bcb5re300lm.dll 
 

Borland C++ + Builder 5

+

cw3250mt.dll

+
bcb5re300lv.dll 
+ +

Note: you can disable automatic library selection by defining +the symbol BOOST_RE_NO_LIB when compiling, this is useful if you +want to statically link even though you're using the dll version +of your run time library, or if you need to debug regex++.

+ +
+ +

Notes for upgraders

+ +

This version of regex++ is the first to be ported to the boost project, and as a result +has a number of changes to comply with the boost coding +guidelines.

+ +

Headers have been changed from <header> or <header.h> +to <boost/header.hpp>

+ +

The library namespace has changed from "jm", to +"boost".

+ +

The reg_xxx algorithms have been renamed regex_xxx (to improve +naming consistency).

+ +

Algorithm query_match has been renamed regex_match, and only +returns true if the expression matches the whole of the input +string (think input data validation).

+ +

Compiling existing code:

+ +

The directory, libs/regex/old_include contains a set of +headers that make this version of regex++ compatible with +previous ones, either add this directory to your include path, or +copy these headers to the root directory of your boost +installation. The contents of these headers are deprecated and +undocumented - really these are just here for existing code - for +new projects use the new header forms.

+ +
+ +

Further Information (Contacts and +Acknowledgements)

+ +

The author can be contacted at John_Maddock@compuserve.com, +the home page for this library is at http://ourworld.compuserve.com/homepages/John_Maddock/regexpp.htm, +and the official boost version can be obtained from www.boost.org/libraries.htm.

+ +

I am indebted to Robert Sedgewick's "Algorithms in C++" +for forcing me to think about algorithms and their performance, +and to the folks at boost for forcing me to think, period. +The following people have all contributed useful comments or +fixes: Dave Abrahams, Mike Allison, Edan Ayal, Jayashree +Balasubramanian, Beman Dawes, Paul Baxter, David Bergman, David +Dennerline, Edward Diener, Peter Dimov, Robert Dunn, Fabio Forno, +Tobias Gabrielsson, Rob Gillen, Marc Gregoire, Chris Hecker, Nick +Hodapp, Jesse Jones, Martin Jost, Boris Krasnovskiy, Jan +Hermelink, Max Leung, Wei-hao Lin, Jens Maurer, Heiko Schmidt, +Scobie Smith, Alexander Sokolovsky, Hervé Poirier, Marc Recht, +Bruno Voigt, Alexey Voinov, Jerry Waldorf, Rob Ward, Lealon +Watts, Thomas Witt and Yuval Yosef. I am also grateful to the +manuals supplied with the Henry Spencer, Perl and GNU regular +expression libraries - wherever possible I have tried to maintain +compatibility with these libraries and with the POSIX standard - +the code however is entirely my own, including any bugs! I can +absolutely guarantee that I will not fix any bugs I don't know +about, so if you have any comments or spot any bugs, please get +in touch.

+ +

Useful further information can be found at:

+ +

A short tutorial on regular expressions can +be found here.

+ +

The Open +Unix Specification contains a wealth of useful material, +including the regular expression syntax, and specifications for <regex.h> +and <nl_types.h>. +

+ +

The Pattern +Matching Pointers site is a "must visit" resource +for anyone interested in pattern matching.

+ +

Glimpse and Agrep, +use a simplified regular expression syntax to achieve faster +search times.

+ +

Udi Manber +and Ricardo Baeza-Yates +both have a selection of useful pattern matching papers available +from their respective web sites.

+ +
+ +

Copyright Dr +John Maddock 1998-2000 all rights reserved.

+ + diff --git a/template_class_ref.htm b/template_class_ref.htm index 8992707c..6c750ce4 100644 --- a/template_class_ref.htm +++ b/template_class_ref.htm @@ -492,291 +492,261 @@ for a container of charT.

}; } // namespace boost -

Class reg_expression has the following public -member functions:

+

Class reg_expression has the following public member functions: +

- - + + - - + + - - + + - - + + - - + - - + const Allocator& a = Allocator()); + - - + + - - + + - - + + - - + - - + + - - + + - - + + - - + string_traits, A>& s, flag_type f = regbase::normal); + - - + flag_type f = regbase::normal); + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + +
 reg_expression(Allocator - a = Allocator()); Constructs - a default instance of reg_expression without any - expression.reg_expression(Allocator a = + Allocator()); Constructs a default + instance of reg_expression without any expression.  
 reg_expression(charT* - p, unsigned f = regbase::normal, Allocator a = - Allocator()); Constructs - an instance of reg_expression from the expression denoted - by the null terminated string p, using the flags f - to determine regular expression syntax. See class regbase for allowable flag values.reg_expression(charT* p, unsigned + f = regbase::normal, Allocator a = Allocator()); Constructs an instance + of reg_expression from the expression denoted by the null + terminated string p, using the flags f to + determine regular expression syntax. See class regbase for allowable flag values.  
 reg_expression(charT* - p1, charT* p2, unsigned f = regbase::normal, - Allocator a = Allocator()); Constructs - an instance of reg_expression from the expression denoted - by pair of iterators p1 and p2, using the - flags f to determine regular expression syntax. - See class regbase for allowable flag values.reg_expression(charT* p1, + charT* p2, unsigned f = regbase::normal, Allocator + a = Allocator()); Constructs an instance + of reg_expression from the expression denoted by pair of + input-iterators p1 and p2, using the flags f + to determine regular expression syntax. See class regbase for allowable flag values.  
 reg_expression(charT* - p, size_type len, unsigned f, Allocator a = - Allocator()); Constructs - an instance of reg_expression from the expression denoted - by the string p of length len, using the - flags f to determine regular expression syntax. - See class regbase for allowable flag values.reg_expression(charT* p, + size_type len, unsigned f, Allocator a = Allocator()); Constructs an instance + of reg_expression from the expression denoted by the + string p of length len, using the flags f + to determine regular expression syntax. See class regbase for allowable flag values.  
 template - <class ST, class SA>
+
template <class + ST, class SA>
reg_expression(const std::basic_string<charT, ST, SA>& p, boost::int_fast32_t f = regbase::normal, - const Allocator& a = Allocator());
 Constructs - an instance of reg_expression from the expression denoted - by the string p, using the flags f to - determine regular expression syntax. See class regbase for allowable flag values.

Note - this member may not be available - depending upon your compiler capabilities.

+ const Allocator& a = Allocator());
 Constructs an instance + of reg_expression from the expression denoted by the + string p, using the flags f to determine + regular expression syntax. See class regbase + for allowable flag values.

Note - this member may not + be available depending upon your compiler capabilities.

 
 template - <class I>
+
template <class I>
reg_expression(I first, I last, flag_type f = regbase::normal, - const Allocator& a = Allocator());
 Constructs - an instance of reg_expression from the expression denoted - by pair of iterators p1 and p2, using the - flags f to determine regular expression syntax. - See class regbase for allowable flag values. Constructs an instance + of reg_expression from the expression denoted by pair of + input-iterators p1 and p2, using the flags f + to determine regular expression syntax. See class regbase for allowable flag values.  
 reg_expression(const - reg_expression&);Copy - constructor - copies an existing regular expression.reg_expression(const + reg_expression&);Copy constructor - copies an + existing regular expression.  
 reg_expression& - operator=(const reg_expression&);Copies an - existing regular expression.reg_expression& operator=(const + reg_expression&);Copies an existing regular + expression.  
 reg_expression& - operator=(const charT* ptr);Equivalent to - assign(ptr);reg_expression& operator=(const + charT* ptr);Equivalent to assign(ptr);  
 template - <class ST, class SA>

reg_expression& - operator=(const std::basic_string<charT, ST, - SA>& p);

+
template <class ST, class + SA>

reg_expression& operator=(const std::basic_string<charT, + ST, SA>& p);

Equivalent to - assign(p);Equivalent to assign(p);  
 reg_expression& - assign(const reg_expression& that);Copies the - regular expression contained by that, throws bad_expression if that does not contain a valid - expression. Returns *this.reg_expression& assign(const + reg_expression& that);Copies the regular + expression contained by that, throws bad_expression if that + does not contain a valid expression. Returns *this.  
 reg_expression& - assign(const charT* p, flag_type f = regbase::normal);Compiles a - regular expression from the expression denoted by the - null terminated string p, using the flags f - to determine regular expression syntax. See class regbase for allowable flag values. Throws bad_expression if p does not contain a valid expression. - Returns *this.reg_expression& assign(const + charT* p, flag_type f = regbase::normal);Compiles a regular + expression from the expression denoted by the null + terminated string p, using the flags f to + determine regular expression syntax. See class regbase for allowable flag values. + Throws bad_expression if p + does not contain a valid expression. Returns *this.  
 reg_expression& - assign(const charT* first, const charT* - last, flag_type f = regbase::normal);Compiles a - regular expression from the expression denoted by the - pair of iterators first-last, using the flags f - to determine regular expression syntax. See class regbase for allowable flag values. Throws bad_expression if first-last does not contain a valid - expression. Returns *this.reg_expression& assign(const + charT* first, const charT* last, flag_type f = + regbase::normal);Compiles a regular + expression from the expression denoted by the pair of + input-iterators first-last, using the flags f + to determine regular expression syntax. See class regbase for allowable flag values. + Throws bad_expression if first-last + does not contain a valid expression. Returns *this.  
 template - <class string_traits, class A>
+
template <class + string_traits, class A>
reg_expression& assign(const std::basic_string<charT, - string_traits, A>& s, flag_type f = regbase::normal);
Compiles a - regular expression from the expression denoted by the - string s, using the flags f to determine - regular expression syntax. See class regbase for allowable flag values. Throws bad_expression if s does not contain a valid expression. - Returns *this.Compiles a regular + expression from the expression denoted by the string s, + using the flags f to determine regular expression + syntax. See class regbase for + allowable flag values. Throws bad_expression + if s does not contain a valid expression. Returns + *this.  
 template - <class iterator>
+
template <class + iterator>
reg_expression& assign(iterator first, iterator last, - flag_type f = regbase::normal);
Compiles a - regular expression from the expression denoted by the - pair of iterators first-last, using the flags f - to determine regular expression syntax. See class regbase for allowable flag values. Throws bad_expression if first-last does not contain a valid - expression. Returns *this.Compiles a regular + expression from the expression denoted by the pair of + input-iterators first-last, using the flags f + to determine regular expression syntax. See class regbase for allowable flag values. + Throws bad_expression if first-last + does not contain a valid expression. Returns *this.  
 Allocator - get_allocator()const;Returns the - allocator used by the expression.Allocator get_allocator()const;Returns the allocator used + by the expression.  
 locale_type - imbue(const locale_type& l);Imbues the - expression with the specified locale, and invalidates the - current expression.locale_type imbue(const + locale_type& l);Imbues the expression with + the specified locale, and invalidates the current + expression.  
 locale_type - getloc()const;Returns the - locale used by the expression.locale_type getloc()const;Returns the locale used by + the expression.  
 flag_type - getflags()const;Returns the - flags used to compile the current expression.flag_type getflags()const;Returns the flags used to + compile the current expression.  
 std::basic_string<charT> - str()const;Returns the - current expression as a string.std::basic_string<charT> + str()const;Returns the current + expression as a string.  
 const_iterator - begin()const;Returns a - pointer to the first character of the current expression.const_iterator begin()const;Returns a pointer to the + first character of the current expression.  
 const_iterator - end()const;Returns a - pointer to the end of the current expression.const_iterator end()const;Returns a pointer to the end + of the current expression.  
 size_type - size()const;Returns the - length of the current expression.size_type size()const;Returns the length of the + current expression.  
 size_type - max_size()const;Returns the - maximum length of a regular expression text.size_type max_size()const;Returns the maximum length + of a regular expression text.  
 bool - empty()const;Returns true - if the object contains no valid expression.bool empty()const;Returns true if the object + contains no valid expression.  
 unsigned - mark_count()const ;Returns the - number of sub-expressions in the compiled regular - expression. Note that this includes the whole match (subexpression - zero), so the value returned is always >= 1.unsigned mark_count()const + ;Returns the number of sub-expressions + in the compiled regular expression. Note that this + includes the whole match (subexpression zero), so the + value returned is always >= 1.  
@@ -785,26 +755,24 @@ member functions:

Class regex_traits

-

#include <boost/regex/regex_traits.hpp>

+

#include <boost/regex/regex_traits.hpp> +

-

This is a preliminary version of the regular -expression traits class, and is subject to change.

+

This is a preliminary version of the regular expression +traits class, and is subject to change.

-

The purpose of the traits class is to make it -easier to customise the behaviour of reg_expression and -the associated matching algorithms. Custom traits classes can -handle special character sets or define additional character -classes, for example one could define [[:kanji:]] as the set of -all (Unicode) kanji characters. This library provides three -traits classes and a wrapper class regex_traits, which -inherits from one of these depending upon the default -localisation model in use, class c_regex_traits -encapsulates the global C locale, class w32_regex_traits +

The purpose of the traits class is to make it easier to +customise the behaviour of reg_expression and the +associated matching algorithms. Custom traits classes can handle +special character sets or define additional character classes, +for example one could define [[:kanji:]] as the set of all (Unicode) +kanji characters. This library provides three traits classes and +a wrapper class regex_traits, which inherits from one of +these depending upon the default localisation model in use, class +c_regex_traits encapsulates the global C locale, class w32_regex_traits encapsulates the global Win32 locale (only available on Win32 systems), and class cpp_regex_traits encapsulates the C++ -locale (only provided if std::locale is supported):

+locale (only provided if std::locale is supported):

template <class charT> class c_regex_traits;
 template<> class c_regex_traits<char> { /*details*/ };
@@ -820,35 +788,33 @@ template<> class cpp_regex_traits<wchar_t> { /*details*/ };
 
 template <class charT> class regex_traits : public base_type { /*detailts*/ };
-

Where "base_type" defaults to w32_regex_traits +

Where "base_type" defaults to w32_regex_traits on Win32 systems, and c_regex_traits otherwise. The default behaviour can be changed by defining one of BOOST_RE_LOCALE_C (forces use of c_regex_traits by default), or BOOST_RE_LOCALE_CPP (forces use of cpp_regex_traits by default). Alternatively a specific traits class can be passed to -the reg_expression template.

+the reg_expression template.

-

The requirements for custom traits classes are documented separately -here....

+

The requirements for custom traits classes are documented separately here....


Class match_results

-

#include <boost/regex.hpp>

+

#include <boost/regex.hpp> +

-

Regular expressions are different from many -simple pattern-matching algorithms in that as well as finding an -overall match they can also produce sub-expression matches: each -sub-expression being delimited in the pattern by a pair of -parenthesis (...). There has to be some method for reporting sub-expression -matches back to the user: this is achieved this by defining a -class match_results that acts as an indexed collection of -sub-expression matches, each sub-expression match being contained -in an object of type sub_match.

+

Regular expressions are different from many simple pattern-matching +algorithms in that as well as finding an overall match they can +also produce sub-expression matches: each sub-expression being +delimited in the pattern by a pair of parenthesis (...). There +has to be some method for reporting sub-expression matches back +to the user: this is achieved this by defining a class match_results +that acts as an indexed collection of sub-expression matches, +each sub-expression match being contained in an object of type sub_match. +

// 
 // class sub_match: 
@@ -905,286 +871,265 @@ in an object of type sub_match. 

typedef match_results<const char*> cmatch; typedef match_results<const wchar_t*> wcmatch;
-

Class match_results is used for reporting what -matched a regular expression, it is passed to the matching -algorithms regex_match and regex_search, and is used by regex_grep to notify the +

Class match_results is used for reporting what matched a +regular expression, it is passed to the matching algorithms regex_match and regex_search, +and is used by regex_grep to notify the callback function (or function object) what matched. Note that the default allocator parameter has been chosen to match the default allocator parameter to reg_expression. match_results has the following public member functions:

- - + + - - + + - - + + - - + n) const; + - - + + - - + + - - + + - - + + - - + + - - + +
 match_results(Allocator - a = Allocator());Constructs an - instance of match_results, using allocator instance a.match_results(Allocator a = + Allocator());Constructs an instance of + match_results, using allocator instance a.  
 match_results(const - match_results& m);Copy - constructor.match_results(const + match_results& m);Copy constructor.  
 match_results& - operator=(const match_results& m);Assignment - operator.match_results& operator=(const + match_results& m);Assignment operator.  
 const + const sub_match<iterator>& operator[](size_type - n) const;Returns what - matched, item 0 represents the whole string, item 1 the - first sub-expression and so on.Returns what matched, item 0 + represents the whole string, item 1 the first sub-expression + and so on.  
 Allocator& - allocator()const;Returns the - allocator used by the class.Allocator& allocator()const;Returns the allocator used + by the class.  
 difference_type - length(unsigned int sub = 0);Returns the - length of the matched subexpression, defaults to the - length of the whole match, in effect this is equivalent - to operator[](sub).second - operator[](sub).first.difference_type length(unsigned + int sub = 0);Returns the length of the + matched subexpression, defaults to the length of the + whole match, in effect this is equivalent to operator[](sub).second + - operator[](sub).first.  
 difference_type - position(unsigned int sub = 0);Returns the - position of the matched sub-expression, defaults to the - position of the whole match. The returned value is the - position of the match relative to the start of the string.difference_type position(unsigned + int sub = 0);Returns the position of the + matched sub-expression, defaults to the position of the + whole match. The returned value is the position of the + match relative to the start of the string.  
 unsigned - int line()const;Returns the - index of the line on which the match occurred, indices - start with 1, not zero. Equivalent to the number of - newline characters prior to operator[](0).first plus one.unsigned int + line()const;Returns the index of the + line on which the match occurred, indices start with 1, + not zero. Equivalent to the number of newline characters + prior to operator[](0).first plus one.  
 iterator - line_start()const;Returns an - iterator denoting the start of the line on which the - match occurred.iterator line_start()const;Returns an iterator denoting + the start of the line on which the match occurred.  
 size_type - size()const;Returns how - many sub-expressions are present in the match, including - sub-expression zero (the whole match). This is the case - even if no matches were found in the search operation - - you must use the returned value from regex_search / regex_match to determine whether any match occured.size_type size()const;Returns how many sub-expressions + are present in the match, including sub-expression zero (the + whole match). This is the case even if no matches were + found in the search operation - you must use the returned + value from regex_search / regex_match to determine whether + any match occured.  
-


+


-

The operator[] member function needs further -explanation: it returns a const reference to a structure of type +

The operator[] member function needs further explanation: it +returns a const reference to a structure of type sub_match<iterator>, which has the following public members:

- - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + +
 typedef - typename std::iterator_traits<iterator>::value_type - value_type;The type - pointed to by the iterators.typedef typename + std::iterator_traits<iterator>::value_type + value_type;The type pointed to by the + iterators.  
 typedef - typename std::iterator_traits<iterator>::difference_type - difference_type;A type that - represents the difference between two iterators.typedef typename + std::iterator_traits<iterator>::difference_type + difference_type;A type that represents the + difference between two iterators.  
 typedef - iterator iterator_type;The iterator - type.typedef iterator + iterator_type;The iterator type.  
 iterator - firstAn iterator - denoting the position of the start of the match.iterator firstAn iterator denoting the + position of the start of the match.  
 iterator - secondAn iterator - denoting the position of the end of the match.iterator secondAn iterator denoting the + position of the end of the match.  
 bool - matchedA Boolean - value denoting whether this sub-expression participated - in the match.bool matchedA Boolean value denoting + whether this sub-expression participated in the match.  
 difference_type - length()const;Returns the - length of the sub-expression match.difference_type length()const;Returns the length of the + sub-expression match.  
 operator - std::basic_string<value_type> ()const;Converts the - sub-expression match into an instance of std::basic_string<>. - Note that this member may be either absent, or present to - a more limited degree depending upon your compiler - capabilities.operator std::basic_string<value_type> + ()const;Converts the sub-expression + match into an instance of std::basic_string<>. Note + that this member may be either absent, or present to a + more limited degree depending upon your compiler + capabilities.  
-

Operator[] takes an integer as an argument that -denotes the sub-expression for which to return information, the -argument can take the following special values:

+

Operator[] takes an integer as an argument that denotes the +sub-expression for which to return information, the argument can +take the following special values:

- - + - - + - - + + - - + - - +
 -2Returns - everything from the end of the match, to the end of the - input string, equivalent to $' in perl. If this is a null - string, then:

first == second

-

And

-

matched == false.

+
-2Returns everything from the + end of the match, to the end of the input string, + equivalent to $' in perl. If this is a null string, then: +

first == second

+

And

+

matched == false.

 
 -1Returns - everything from the start of the input string (or the end - of the last match if this is a grep operation), to the - start of this match. Equivalent to $` in perl. If this is - a null string, then:

first == - second

-

And

-

matched == false.

+
-1Returns everything from the + start of the input string (or the end of the last match + if this is a grep operation), to the start of this match. + Equivalent to $` in perl. If this is a null string, then: +

first == second

+

And

+

matched == false.

 
 0Returns the - whole of what matched, equivalent to $& in perl. The - matched parameter is always true.0Returns the whole of what + matched, equivalent to $& in perl. The matched + parameter is always true.  
 0 < N < - size()Returns what - matched sub-expression N, if this sub-expression did not - participate in the match then 

matched == false

-

otherwise:

-

matched == true.

+
0 < N < size()Returns what matched sub-expression + N, if this sub-expression did not participate in the + match then 

matched == false

+

otherwise:

+

matched == true.

 
 N < -2 or - N >= size()Represents an - out-of range non-existent sub-expression. Returns a - "null" match in which

first - == last

-

And

-

matched == false.

+
N < -2 or N >= size()Represents an out-of range + non-existent sub-expression. Returns a "null" + match in which

first == last

+

And

+

matched == false.

 
-

Note that as well as being parameterised for an -allocator, match_results<> also takes an iterator type, -this allows any pair of iterators to be searched for a given -regular expression, provided the iterators have at least bi-directional -properties.

+

Note that as well as being parameterised for an allocator, +match_results<> also takes an iterator type, this allows +any pair of iterators to be searched for a given regular +expression, provided the iterators have at least bi-directional +properties.


Algorithm regex_match

-

#include <boost/regex.hpp>

+

#include <boost/regex.hpp> +

-

The algorithm regex _match determines whether a -given regular expression matches a given sequence denoted by a -pair of iterators, the algorithm is defined as follows, note that -the result is true only if the expression matches the whole of -the input sequence, the main use of this function is data input -validation:

+

The algorithm regex _match determines whether a given regular +expression matches a given sequence denoted by a pair of +bidirectional-iterators, the algorithm is defined as follows, +note that the result is true only if the expression matches the +whole of the input sequence, the main use of this function is +data input validation:

template <class iterator, class Allocator, class charT, class traits, class Allocator2>
 bool regex_match(iterator first, 
@@ -1193,12 +1138,11 @@ validation: 

                 const reg_expression<charT, traits, Allocator2>& e,                   unsigned flags = match_default);
-

The library also defines the following -convenience versions, which take either a const charT*, or a -const std::basic_string<>& in place of a pair of -iterators [note - these versions may not be available, or may be -available in a more limited form, depending upon your compilers -capabilities]:

+

The library also defines the following convenience versions, +which take either a const charT*, or a const std::basic_string<>& +in place of a pair of iterators [note - these versions may not be +available, or may be available in a more limited form, depending +upon your compilers capabilities]:

template <class charT, class Allocator, class traits, class Allocator2>
 bool regex_match(const charT* str, 
@@ -1212,9 +1156,8 @@ capabilities]: 

                 const reg_expression<charT, traits, Allocator2>& e,                   unsigned flags = match_default);
-

Finally there is a set of convenience versions -that simply return true or false and do not indicate what matched: -

+

Finally there is a set of convenience versions that simply +return true or false and do not indicate what matched:

template <class iterator, class Allocator, class charT, class traits, class Allocator2>
 bool regex_match(iterator first, 
@@ -1232,64 +1175,61 @@ that simply return true or false and do not indicate what matched:
                  const reg_expression<charT, traits, Allocator2>& e, 
                  unsigned flags = match_default);
-

The parameters for the main function version -are as follows:

+

The parameters for the main function version are as follows:

- - + + - - + + - - + + - - + + - - + +
 iterator firstDenotes the start of the range to be - matched.iterator firstDenotes the start of the range to be matched.  
 iterator lastDenotes the - end of the range to be matched.iterator lastDenotes the end of the range + to be matched.  
 match_results<iterator, - Allocator>& mAn instance - of match_results in which what matched will be reported. - On exit if a match occurred then m[0] denotes the whole - of the string that matched, m[0].first must be equal to - first, m[0].second will be less than or equal to last. m[1] - denotes the first subexpression m[2] the second - subexpression and so on. If no match occurred then m[0].first - = m[0].second = last.match_results<iterator, + Allocator>& mAn instance of match_results + in which what matched will be reported. On exit if a + match occurred then m[0] denotes the whole of the string + that matched, m[0].first must be equal to first, m[0].second + will be less than or equal to last. m[1] denotes the + first subexpression m[2] the second subexpression and so + on. If no match occurred then m[0].first = m[0].second = + last.  
 const - reg_expression<charT, traits, Allocator2>& eContains the - regular expression to be matched.const + reg_expression<charT, traits, Allocator2>& eContains the regular + expression to be matched.  
 unsigned - flags = match_defaultDetermines - the semantics used for matching, a combination of one or - more match_flags enumerators.unsigned flags = + match_defaultDetermines the semantics + used for matching, a combination of one or more match_flags enumerators.  
-

regex_match returns false if no match occurs or -true if it does. A match only occurs if it starts at first -and finishes at last. Example: the following example processes an ftp response:

+

regex_match returns false if no match occurs or true if it +does. A match only occurs if it starts at first and +finishes at last. Example: the following example +processes an ftp response:

#include <stdlib.h> 
 #include <boost/regex.hpp> 
@@ -1322,134 +1262,126 @@ regex expression("([0-9]+)(\\-| |$)(.*)")
    return -1; 
 }
-

The value of the flags -parameter passed to the algorithm must be a combination of one or -more of the following values:

+

The value of the flags parameter +passed to the algorithm must be a combination of one or more of +the following values:

- - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + +
 match_defaultThe default - value, indicates that first represents the start - of a line, the start of a buffer, and (possibly) the - start of a word. Also implies that last represents - the end of a line, the end of the buffer and (possibly) - the end of a word. Implies that a dot sub-expression - "." will match both the newline character and a - null.match_defaultThe default value, indicates + that first represents the start of a line, the + start of a buffer, and (possibly) the start of a word. + Also implies that last represents the end of a + line, the end of the buffer and (possibly) the end of a + word. Implies that a dot sub-expression "." + will match both the newline character and a null.  
 match_not_bolWhen this - flag is set then first does not represent the - start of a new line.match_not_bolWhen this flag is set then first + does not represent the start of a new line.  
 match_not_eolWhen this - flag is set then last does not represent the end - of a line.match_not_eolWhen this flag is set then last + does not represent the end of a line.  
 match_not_bobWhen this - flag is set then first is not the beginning of a - buffer.match_not_bobWhen this flag is set then first + is not the beginning of a buffer.  
 match_not_eobWhen this - flag is set then last does not represent the end - of a buffer.match_not_eobWhen this flag is set then last + does not represent the end of a buffer.  
 match_not_bowWhen this - flag is set then first can never match the start - of a word.match_not_bowWhen this flag is set then first + can never match the start of a word.  
 match_not_eowWhen this - flag is set then last can never match the end of a - word.match_not_eowWhen this flag is set then last + can never match the end of a word.  
 match_not_dot_newlineWhen this - flag is set then a dot expression "." can not - match the newline character.match_not_dot_newlineWhen this flag is set then a + dot expression "." can not match the newline + character.  
 match_not_dot_nullWhen this - flag is set then a dot expression "." can not - match a null character.match_not_dot_nullWhen this flag is set then a + dot expression "." can not match a null + character.  
 match_prev_availWhen - this flag is set, then *--first is a valid - expression and the flags match_not_bol and match_not_bow - have no effect, since the value of the previous character - can be used to check these.match_prev_availWhen this flag + is set, then *--first is a valid expression and + the flags match_not_bol and match_not_bow have no effect, + since the value of the previous character can be used to + check these.  
 match_anyWhen - this flag is set, then the first string matched is - returned, rather than the longest possible match. This - flag can significantly reduce the time taken to find a - match, but what matches is undefined.match_anyWhen this flag + is set, then the first string matched is returned, rather + than the longest possible match. This flag can + significantly reduce the time taken to find a match, but + what matches is undefined.  
 match_not_nullWhen - this flag is set, then the expression will never match a - null string.match_not_nullWhen this flag + is set, then the expression will never match a null + string.  
 match_continuousWhen - this flags is set, then during a grep operation, each - successive match must start from where the previous match - finished.match_continuousWhen this flags + is set, then during a grep operation, each successive + match must start from where the previous match finished.  
 match_partialWhen - this flag is set, the regex algorithms will report partial matches - - that is where one or more characters at the end of the - text input matched some prefix of the regular expression.match_partialWhen this flag + is set, the regex algorithms will report partial matches - that is + where one or more characters at the end of the text input + matched some prefix of the regular expression.  
@@ -1460,15 +1392,14 @@ more of the following values:

Algorithm regex_search

-

 #include <boost/regex.hpp>

+

 #include <boost/regex.hpp> +

-

The algorithm regex_search will search a range -denoted by a pair of iterators for a given regular expression. +

The algorithm regex_search will search a range denoted by a +pair of bidirectional-iterators for a given regular expression. The algorithm uses various heuristics to reduce the search time by only checking for a match if a match could conceivably start -at that position. The algorithm is defined as follows:

+at that position. The algorithm is defined as follows:

template <class iterator, class Allocator, class charT, class traits, class Allocator2>
 bool regex_search(iterator first, 
@@ -1477,12 +1408,11 @@ at that position. The algorithm is defined as follows: 

                const reg_expression<charT, traits, Allocator2>& e,                  unsigned flags = match_default);
-

The library also defines the following -convenience versions, which take either a const charT*, or a -const std::basic_string<>& in place of a pair of -iterators [note - these versions may not be available, or may be -available in a more limited form, depending upon your compilers -capabilities]:

+

The library also defines the following convenience versions, +which take either a const charT*, or a const std::basic_string<>& +in place of a pair of iterators [note - these versions may not be +available, or may be available in a more limited form, depending +upon your compilers capabilities]:

template <class charT, class Allocator, class traits, class Allocator2>
 bool regex_search(const charT* str, 
@@ -1496,71 +1426,66 @@ capabilities]: 

                const reg_expression<charT, traits, Allocator2>& e,                  unsigned flags = match_default);
-

The parameters for the main function version -are as follows:

+

The parameters for the main function version are as follows:

- - + + - - + + - - + + - - + + - - + +
 iterator - firstThe starting - position of the range to search.iterator firstThe starting position of the + range to search.  
 iterator lastThe ending - position of the range to search.iterator lastThe ending position of the + range to search.  
 match_results<iterator, - Allocator>& mAn instance - of match_results in which what matched will be reported. - On exit if a match occurred then m[0] denotes the whole - of the string that matched, m[0].first and m[0].second - will be less than or equal to last. m[1] denotes the - first sub-expression m[2] the second sub-expression and - so on. If no match occurred then m[0].first = m[0].second - = last.match_results<iterator, + Allocator>& mAn instance of match_results + in which what matched will be reported. On exit if a + match occurred then m[0] denotes the whole of the string + that matched, m[0].first and m[0].second will be less + than or equal to last. m[1] denotes the first sub-expression + m[2] the second sub-expression and so on. If no match + occurred then m[0].first = m[0].second = last.  
 const - reg_expression<charT, traits, Allocator2>& eThe regular - expression to search for.const + reg_expression<charT, traits, Allocator2>& eThe regular expression to + search for.  
 unsigned - flags = match_defaultThe flags - that determine what gets matched, a combination of one or - more match_flags enumerators.unsigned flags = + match_defaultThe flags that determine + what gets matched, a combination of one or more match_flags enumerators.  
-


+


-

Example: the following example, takes the contents of a file in the form of a string, -and searches for all the C++ class declarations in the file. The -code will work regardless of the way that std::string is -implemented, for example it could easily be modified to work with -the SGI rope class, which uses a non-contiguous storage strategy. -

+

Example: the following example, +takes the contents of a file in the form of a string, and +searches for all the C++ class declarations in the file. The code +will work regardless of the way that std::string is implemented, +for example it could easily be modified to work with the SGI rope +class, which uses a non-contiguous storage strategy.

#include <string> 
 #include <map> 
@@ -1602,13 +1527,12 @@ void IndexClasses(map_type& m, const std::string& file)
 
 

Algorithm regex_grep

-

#include <boost/regex.hpp>

+

#include <boost/regex.hpp> +

-

 Regex_grep allows you to search through -an iterator range and locate all the (non-overlapping) matches -with a given regular expression. The function is declared as:

+

 Regex_grep allows you to search through a bidirectional-iterator +range and locate all the (non-overlapping) matches with a given +regular expression. The function is declared as:

template <class Predicate, class iterator, class charT, class traits, class Allocator>
 unsigned int regex_grep(Predicate foo, 
@@ -1617,12 +1541,11 @@ with a given regular expression. The function is declared as: 

                        const reg_expression<charT, traits, Allocator>& e,                          unsigned flags = match_default)
-

The library also defines the following -convenience versions, which take either a const charT*, or a -const std::basic_string<>& in place of a pair of -iterators [note - these versions may not be available, or may be -available in a more limited form, depending upon your compilers -capabilities]:

+

The library also defines the following convenience versions, +which take either a const charT*, or a const std::basic_string<>& +in place of a pair of iterators [note - these versions may not be +available, or may be available in a more limited form, depending +upon your compilers capabilities]:

template <class Predicate, class charT, class Allocator, class traits>
 unsigned int regex_grep(Predicate foo, 
@@ -1636,84 +1559,82 @@ capabilities]: 

              const reg_expression<charT, traits, Allocator>& e,                unsigned flags = match_default);
-

The parameters for the primary version of -regex_grep have the following meanings:

+

The parameters for the primary version of regex_grep have the +following meanings:

- - + + - - + + - - + + - - + + - - + +
 fooA predicate - function object or function pointer, see below for more - information.fooA predicate function object + or function pointer, see below for more information.  
 firstThe start of - the range to search.firstThe start of the range to + search.  
 lastThe end of - the range to search.lastThe end of the range to + search.  
 eThe regular - expression to search for.eThe regular expression to + search for.  
 flagsThe flags - that determine how matching is carried out, one of the match_flags enumerators.flagsThe flags that determine how + matching is carried out, one of the match_flags + enumerators.  
-

 The algorithm finds all of the non-overlapping -matches of the expression e, for each match it fills a match_results<iterator, Allocator> structure, which contains -information on what matched, and calls the predicate foo, passing -the match_results<iterator, Allocator> as a single argument. -If the predicate returns true, then the grep operation continues, -otherwise it terminates without searching for further matches. -The function returns the number of matches found.

+

 The algorithm finds all of the non-overlapping matches +of the expression e, for each match it fills a match_results<iterator, Allocator> +structure, which contains information on what matched, and calls +the predicate foo, passing the match_results<iterator, +Allocator> as a single argument. If the predicate returns +true, then the grep operation continues, otherwise it terminates +without searching for further matches. The function returns the +number of matches found.

-

The general form of the predicate is:

+

The general form of the predicate is:

struct grep_predicate
 {
    bool operator()(const match_results<iterator_type, expression_type::alloc_type>& m);
 };
-

For example the regular expression "a*b" -would find one match in the string "aaaaab" and two in -the string "aaabb".

+

For example the regular expression "a*b" would find +one match in the string "aaaaab" and two in the string +"aaabb".

-

Remember this algorithm can be used for a lot -more than implementing a version of grep, the predicate can be -and do anything that you want, grep utilities would output the -results to the screen, another program could index a file based -on a regular expression and store a set of bookmarks in a list, -or a text file conversion utility would output to file. The -results of one regex_grep can even be chained into another -regex_grep to create recursive parsers.

+

Remember this algorithm can be used for a lot more than +implementing a version of grep, the predicate can be and do +anything that you want, grep utilities would output the results +to the screen, another program could index a file based on a +regular expression and store a set of bookmarks in a list, or a +text file conversion utility would output to file. The results of +one regex_grep can even be chained into another regex_grep to +create recursive parsers.

-

Example: convert the example -from regex_search to use regex_grep instead:

+

Example: +convert the example from regex_search to use regex_grep +instead:

#include <string> 
 #include <map> 
@@ -1756,9 +1677,8 @@ void IndexClasses(map_type& m, const std::string& file)
    regex_grep(IndexClassesPred(m, start), start, end, expression); 
 } 
-

Example: Use regex_grep to -call a global callback function:

+

Example: +Use regex_grep to call a global callback function:

#include <string> 
 #include <map> 
@@ -1797,11 +1717,10 @@ void IndexClasses(const std::string& file)
 }
   
-

Example: use regex_grep to -call a class member function, use the standard library adapters std::mem_fun -and std::bind1st to convert the member function into a -predicate:

+

Example: +use regex_grep to call a class member function, use the standard +library adapters std::mem_fun and std::bind1st to +convert the member function into a predicate:

#include <string> 
 #include <map> 
@@ -1857,9 +1776,9 @@ bool class_index::grep_callback(boost::match_results<std::string::const_i
 } 
   
-

Finally, C++ Builder users can -use C++ Builder's closure type as a callback argument:

+

Finally, +C++ Builder users can use C++ Builder's closure type as a +callback argument:

#include <string> 
 #include <map> 
@@ -1920,15 +1839,13 @@ index[std::string(what[5].first, what[5].second) + std::string(what[6].first, wh
 
 

 Algorithm regex_format

-

#include <boost/regex.hpp>

+

#include <boost/regex.hpp> +

-

The algorithm regex_format takes the results of -a match and creates a new string based upon a format -string, regex_format can be used for -search and replace operations:

+

The algorithm regex_format takes the results of a match and +creates a new string based upon a format string, +regex_format can be used for search and replace operations:

template <class OutputIterator, class iterator, class Allocator, class charT>
 OutputIterator regex_format(OutputIterator out,
@@ -1942,11 +1859,11 @@ OutputIterator regex_format(OutputIterator out,
                             const std::basic_string<charT>& fmt,
                             unsigned flags = 0);
-

The library also defines the following -convenience variation of regex_format, which returns the result -directly as a string, rather than outputting to an iterator [note -- this version may not be available, or may be available in a -more limited form, depending upon your compilers capabilities]:

+

The library also defines the following convenience variation +of regex_format, which returns the result directly as a string, +rather than outputting to an iterator [note - this version may +not be available, or may be available in a more limited form, +depending upon your compilers capabilities]:

template <class iterator, class Allocator, class charT>
 std::basic_string<charT> regex_format
@@ -1960,82 +1877,77 @@ std::basic_string<charT> regex_format
                                   const std::basic_string<charT>& fmt,
                                   unsigned flags = 0);
-

Parameters to the main version of the function -are passed as follows:

+

Parameters to the main version of the function are passed as +follows:

- - + + - - + + - - + + - - + +
 OutputIterator - outAn output - iterator type, the output string is sent to this iterator. - Typically this would be a std::ostream_iterator.OutputIterator outAn output iterator type, the + output string is sent to this iterator. Typically this + would be a std::ostream_iterator.  
 const - match_results<iterator, Allocator>& mAn instance - of match_results<> obtained from one of the - matching algorithms above, and denoting what matched.const + match_results<iterator, Allocator>& mAn instance of + match_results<> obtained from one of the matching + algorithms above, and denoting what matched.  
 const - charT* fmtA format - string that determines how the match is transformed into - the new string.const charT* fmtA format string that + determines how the match is transformed into the new + string.  
 unsigned - flagsOptional - flags which describe how the format string is to be - interpreted.unsigned flagsOptional flags which + describe how the format string is to be interpreted.  
-

Format flags are -defined as follows:

+

Format flags are defined as follows: +

- - + + - - + + - - + + - - + + @@ -2047,35 +1959,31 @@ defined as follows:
 format_allEnables all - syntax options (perl-like plus extentions).format_allEnables all syntax options (perl-like + plus extentions).  
 format_sedAllows only a - sed-like syntax.format_sedAllows only a sed-like + syntax.  
 format_perlAllows only a - perl-like syntax.format_perlAllows only a perl-like + syntax.  
 format_no_copyDisables - copying of unmatched sections to the output string during - regex_merge operations.format_no_copyDisables copying of + unmatched sections to the output string during regex_merge operations.  
-


+


-

The format string syntax (and available options) -is described more fully under format -strings.

+

The format string syntax (and available options) is described +more fully under format +strings.


Algorithm regex_merge

-

#include <boost/regex.hpp>

+

#include <boost/regex.hpp> +

-

The algorithm regex_merge is a combination of regex_grep and regex_format. That is, it greps through the string finding all the -matches to the regular expression, for each match it then calls regex_format to format the string and sends the result to the output -iterator. Sections of text that do not match are copied to the -output unchanged only if the flags parameter does not have the -flag format_no_copy set. If the flag format_first_only is set then -only the first occurance is replaced rather than all occurances.

+

The algorithm regex_merge is a combination of regex_grep and regex_format. +That is, it greps through the string finding all the matches to +the regular expression, for each match it then calls regex_format to format the string and +sends the result to the output iterator. Sections of text that do +not match are copied to the output unchanged only if the flags +parameter does not have the flag format_no_copy +set. If the flag format_first_only is +set then only the first occurance is replaced rather than all +occurances.

template <class OutputIterator, class iterator, class traits, class Allocator, class charT>
 OutputIterator regex_merge(OutputIterator out, 
@@ -2093,11 +2001,11 @@ OutputIterator regex_merge(OutputIterator out, 
                            std::basic_string<charT>& fmt, 
                            unsigned int flags = match_default);
-

The library also defines the following -convenience variation of regex_merge, which returns the result -directly as a string, rather than outputting to an iterator [note -- this version may not be available, or may be available in a -more limited form, depending upon your compilers capabilities]:

+

The library also defines the following convenience variation +of regex_merge, which returns the result directly as a string, +rather than outputting to an iterator [note - this version may +not be available, or may be available in a more limited form, +depending upon your compilers capabilities]:

template <class traits, class Allocator, class charT>
 std::basic_string<charT> regex_merge(const std::basic_string<charT>& text,
@@ -2111,69 +2019,63 @@ std::basic_string<charT> regex_merge(const std::basic_string<cha
                                      const std::basic_string<charT>& fmt, 
                                      unsigned int flags = match_default);
-

Parameters to the main version of the function -are passed as follows:

+

Parameters to the main version of the function are passed as +follows:

- - + + - - + + - - + + - - + + - - + + - - + +
 OutputIterator - outAn output - iterator type, the output string is sent to this iterator. - Typically this would be a std::ostream_iterator.OutputIterator outAn output iterator type, the + output string is sent to this iterator. Typically this + would be a std::ostream_iterator.  
 iterator - firstThe start of - the range of text to grep.iterator firstThe start of the range of + text to grep (bidirectional-iterator).  
 iterator lastThe end of - the range of text to grep.iterator lastThe end of the range of text + to grep (bidirectional-iterator).  
 const - reg_expression<charT, traits, Allocator>& eThe - expression to search for.const + reg_expression<charT, traits, Allocator>& eThe expression to search for.  
 const - charT* fmtThe format - string to be applied to sections of text that match.const charT* fmtThe format string to be + applied to sections of text that match.  
 unsigned - int flags = match_defaultFlags which - determine how the expression is matched - see match_flags, and how the format string is interpreted - see - format_flags.unsigned int + flags = match_defaultFlags which determine how + the expression is matched - see match_flags, + and how the format string is interpreted - see format_flags.  
-

Example: the following example takes C/C++ source code as input, and outputs syntax -highlighted HTML code.

+

Example: the following example takes +C/C++ source code as input, and outputs syntax highlighted HTML +code.

 #include <fstream>
@@ -2287,13 +2189,11 @@ color="#0000FF">"(?1<)(?2>)";
 
 

Algorithm regex_split

-

#include <boost/regex.hpp>

+

#include <boost/regex.hpp> +

-

Algorithm regex_split performs a similar -operation to the perl split operation, and comes in three -overloaded forms:

+

Algorithm regex_split performs a similar operation to the perl +split operation, and comes in three overloaded forms:

template <class OutputIterator, class charT, class Traits1, class Alloc1, class Traits2, class Alloc2>
 std::size_t regex_split(OutputIterator out, 
@@ -2312,36 +2212,33 @@ std::size_t regex_split(OutputIterator out, 
 std::size_t regex_split(OutputIterator out, 
                         std::basic_string<charT, Traits1, Alloc1>& s);
-

Each version takes an output-iterator for -output, and a string for input. If the expression contains no -marked sub-expressions, then the algorithm writes one string onto -the output-iterator for each section of input that does not match -the expression. If the expression does contain marked sub-expressions, -then each time a match is found, one string for each marked sub-expression -will be written to the output-iterator. No more than max_split -strings will be written to the output-iterator. Before -returning, all the input processed will be deleted from the -string s (if max_split is not reached then all of s -will be deleted). Returns the number of strings written to the -output-iterator. If the parameter max_split is not -specified then it defaults to UINT_MAX. If no expression is -specified, then it defaults to "\s+", and splitting -occurs on whitespace.

+

Each version takes an output-iterator for output, and a string +for input. If the expression contains no marked sub-expressions, +then the algorithm writes one string onto the output-iterator for +each section of input that does not match the expression. If the +expression does contain marked sub-expressions, then each time a +match is found, one string for each marked sub-expression will be +written to the output-iterator. No more than max_split strings +will be written to the output-iterator. Before returning, all the +input processed will be deleted from the string s (if max_split +is not reached then all of s will be deleted). Returns +the number of strings written to the output-iterator. If the +parameter max_split is not specified then it defaults to +UINT_MAX. If no expression is specified, then it defaults to +"\s+", and splitting occurs on whitespace.

-

Example: the following -function will split the input string into a series of tokens, and -remove each token from the string s:

+

Example: +the following function will split the input string into a series +of tokens, and remove each token from the string s:

unsigned tokenise(std::list<std::string>& l, std::string& s)
 {
    return boost::regex_split(std::back_inserter(l), s);
 }
-

Example: the following short -program will extract all of the URL's from a html file, and print -them out to cout:

+

Example: +the following short program will extract all of the URL's from a +html file, and print them out to cout:

#include <list>
 #include <fstream>
@@ -2552,10 +2449,7 @@ void search(std::istream& is)
 
 
-

Copyright Dr -John Maddock 1998-2001 all -rights reserved.

+

Copyright Dr +John Maddock 1998-2001 all rights reserved.

-