--- code/trunk/doc/html/pcrecpp.html 2007/02/24 21:40:59 81 +++ code/trunk/doc/html/pcrecpp.html 2012/01/14 11:16:23 869 @@ -16,26 +16,27 @@
#include <pcrecpp.h>
--
The C++ wrapper for PCRE was provided by Google Inc. Some additional functionality was added by Giuseppe Maxia. This brief man page was constructed from the notes in the pcrecpp.h file, which should be consulted for -further details. +further details. Note that the C++ wrapper supports only the original 8-bit +PCRE library. There is no 16-bit support at present.
@@ -101,16 +102,43 @@ c. The "i"th argument has a suitable type for holding the string captured as the "i"th sub-pattern. If you pass in - NULL for the "i"th argument, or pass fewer arguments than + void * NULL for the "i"th argument, or a non-void * NULL + of the correct type, or pass fewer arguments than the number of sub-patterns, "i"th captured sub-pattern is ignored. +CAVEAT: An optional sub-pattern that does not exist in the matched +string is assigned the empty string. Therefore, the following will +return false (because the empty string is not a valid number): +
+ int number;
+ pcrecpp::RE::FullMatch("abc", "[a-z]+(\\d+)?", &number);
+
The matching interface supports at most 16 arguments per call.
If you need more, consider using the more general interface
pcrecpp::RE::DoMatch. See pcrecpp.h for the signature for
DoMatch.
-+NOTE: Do not use no_arg, which is used internally to mark the end of a +list of optional arguments, as a placeholder for missing arguments, as this can +lead to segfaults. +
++You can use the "QuoteMeta" operation to insert backslashes before all +potentially meaningful characters in a string. The returned string, used as a +regular expression, will exactly match the original string. +
+ Example: + string quoted = RE::QuoteMeta(unquoted); ++Note that it's legal to escape a character even if it has no special meaning in +a regular expression -- so this function does that. (This also makes it +identical to the perl function of the same name; see "perldoc -f quotemeta".) +For example, "1.5-2.0?" becomes "1\.5\-2\.0\?". + +
You can use the "PartialMatch" operation when you want the pattern to match any substring of the text. @@ -125,7 +153,7 @@ assert(number == 100);
-By default, pattern and text are plain text, one byte per character. The UTF8 flag, passed to the constructor, causes both pattern and string to be treated @@ -150,7 +178,7 @@ --enable-utf8 flag.
-PCRE defines some modifiers to change the behavior of the regular expression engine. The C++ wrapper defines an auxiliary class, RE_Options, as a vehicle to @@ -188,20 +216,24 @@
RE_Options & set_caseless(bool)-which sets or unsets the modifier. Moreover, PCRE_CONFIG_MATCH_LIMIT can be +which sets or unsets the modifier. Moreover, PCRE_EXTRA_MATCH_LIMIT can be accessed through the set_match_limit() and match_limit() member functions. Setting match_limit to a non-zero value will limit the execution of pcre to keep it from doing bad things like blowing the stack or taking an eternity to return a result. A value of 5000 is good enough to stop stack blowup in a 2MB thread stack. Setting match_limit to zero disables -match limiting. +match limiting. Alternatively, you can call match_limit_recursion() +which uses PCRE_EXTRA_MATCH_LIMIT_RECURSION to limit how much PCRE +recurses. match_limit() limits the number of matches PCRE does; +match_limit_recursion() limits the depth of internal recursion, and +therefore the amount of stack that is used.
Normally, to pass one or more modifiers to a RE class, you declare a RE_Options object, set the appropriate options, and pass this object to a RE constructor. Example:
- RE_options opt;
+ RE_Options opt;
opt.set_caseless(true);
if (RE("HELLO", opt).PartialMatch("hello world")) ...
@@ -240,7 +272,7 @@
-The "Consume" operation may be useful if you want to repeatedly match regular expressions at the front of a string and skip over @@ -251,10 +283,7 @@ Example: read lines of the form "var = value" from a string. string contents = ...; // Fill string somehow pcrecpp::StringPiece input(contents); // Wrap in a StringPiece - -
--
+
string var;
int value;
pcrecpp::RE re("(\\w+) = (\\d+)\n");
@@ -273,7 +302,7 @@
pcrecpp::RE("(\\w+)").FindAndConsume(&input, &word)
-By default, if you pass a pointer to a numeric value, the corresponding text is interpreted as a base-10 number. You can @@ -291,7 +320,7 @@ will leave 64 in a, b, c, and d.
-You can replace the first match of "pattern" in "str" with "rewrite". Within "rewrite", backslash-escaped digits (\1 to \9) can be @@ -323,11 +352,17 @@ occurred and the extraction happened successfully; if no match occurs, the string is left unaffected.
-
The C++ wrapper was contributed by Google Inc.
-Copyright © 2005 Google Inc.
+Copyright © 2007 Google Inc.
+
+
+Last updated: 08 January 2012
+
Return to the PCRE index page.