Main Page Class Hierarchy Compound List File List Compound Members File Members
Pcre Class Reference
#include <pcre++.h>
List of all members.
Detailed Description
The Pcre class is a wrapper around the PCRE library.
The library "pcre++" defines a class named "Pcre" which you can use to search in strings using reular expressions as well as getting matched sub strings. It does currently not support all features, which the underlying PCRE library provides, but the most important stuff is implemented.
Please study this example code to learn how to use this class:
#include <pcre++.h>
#include <iostream>
int main() {
try {
string expression = "([a-z]*) ([0-9]+)";
string stuff = "hallo 11 robert";
Pcre reg(expression, "i");
if(reg.search(stuff) == true) {
if(reg.num_matches >= 1) {
cout << "matched " << reg.matches() << " times:" << endl;
for(int pos=0; pos < reg.matches(); pos++) {
cout << " match " << pos << ": " << reg.get_match(pos) << endl;
cout << " start: " << reg.get_match_start(pos) << ", end: " << reg.get_match_end(pos) << endl;
}
}
else {
cout << "it matched, but there where no substrings." << endl;
}
}
else {
cout << "didn't match." << endl;
}
}
catch (Exception E) {
cerr << E.mout() << endl;
exit(-1);
}
exit(0);
}
Compile your programs which use the prce++ class using the following LDFLAGS:
g++ yourcode.o .. -L/path/to/the/lib -lpcrepp -o yourprogram
If you want to learn more about regular expressions which can be used with pcre++, then please read the following documentation: perlre - Perl regular expressions
The pcre library itself does also contain some usefull documentation, which maybe interesting for you: PCRE manual page
Definition at line 92 of file pcre++.h.
Constructor & Destructor Documentation
Pcre::Pcre (
|
const string & expression )
|
|
|
Constructor. Compile the given pattern. An Pcre object created this way can be used multiple times to do searches. -
Parameters:
-
string expression
|
a string, which must be a valid perl regular expression. |
-
Returns:
-
A new Pcre object, which holds te compiled pattern.
-
See also:
-
Pcre(const string& _expression, const string& flags)
|
Pcre::Pcre (
|
const string & _expression,
|
|
const string & flags )
|
|
|
Constructor. Compile the given pattern. An Pcre object created this way can be used multiple times to do searches. -
Parameters:
-
string expression
|
a string, which must be a valid perl regular expression. |
string flags
|
can be one or more of the following letters:
|
- i Search case insensitive.
- m Match on multiple lines, thus ^ and $ are interpreted as the start and end of the entire string, not of a single line.
- s A dot in an expression matches newlines too(which is normally not the case).
- x Whitespace characters will be ignored (except within character classes or if escaped).
-
Returns:
-
A new Pcre object, which holds te compiled pattern.
-
See also:
-
Pcre(const string& expression)
|
|
Copy Constructor Creates a new Pcre object of an existing one. -
Parameters:
-
Pcre P
|
an existing Pcre object. |
-
Returns:
-
A new Pcre object, which holds te compiled pattern.
-
See also:
-
Pcre(const string& expression) , Pcre(const string& expression, const string& flags)
|
|
Destructor. The desturcor will automatically invoked if the object is no more used. It frees all the memory allocated by pcre++. |
Member Function Documentation
string Pcre::get_match (
|
int pos )
|
|
|
Get a substring at a known position. This method throws an out-of-range exception if the given position is invalid. -
Parameters:
-
int pos
|
the position of the substring to return. Identical to perl's $1..$n. |
-
Returns:
-
the substring at the given position.
Example: string mysub = regex.get_match(1); Get the first substring that metched the expression in the "regex" object. |
int Pcre::get_match_end (
|
int pos )
|
|
|
Get the end position of a substring within the searched string. This method returns the character position of the last character of a substring withing the searched string. -
Parameters:
-
int pos
|
the position of the substring. Identical to perl's $1..$n. |
-
Returns:
-
the integer character position of the last character of a substring. Positions are starting at 0.
Example: -
See also:
-
int get_match_start(int pos)
|
int Pcre::get_match_start (
|
int pos )
|
|
|
Get the start position of a substring within the searched string. This method returns the character position of the first character of a substring withing the searched string. -
Parameters:
-
int pos
|
the position of the substring. Identical to perl's $1..$n. |
-
Returns:
-
the integer character position of the first character of a substring. Positions are starting at 0.
Example: -
See also:
-
int get_match_end(int pos)
|
|
Return a vector of substrings, if any. -
Returns:
-
a pointer to a ResultSet, which may be NULL, if no substrings has been found.
-
See also:
-
ResultSet
|
bool Pcre::matched (
|
) [inline]
|
|
|
Test if a search was successfull. This method must be invoked after calling search(). -
Returns:
-
boolean true if the search was successfull at all, or false if not.
Definition at line 261 of file pcre++.h. |
int Pcre::matches (
|
) [inline]
|
|
|
Get the number of substrings generated by pcre++. -
Returns:
-
the number of substrings generated by pcre++.
Definition at line 266 of file pcre++.h. |
const Pcre & Pcre::operator= (
|
const string & expression )
|
|
|
Operator =. -
Parameters:
-
string expression
|
a valid regular expression. |
-
Returns:
-
a new Pcre object.
Example:
Pcre regex = "(A+?)";
@codeend; |
bool Pcre::search (
|
const string & stuff,
|
|
int OffSet )
|
|
|
Do a search on the given string beginning at the given offset. This method does the actual search on the given string. -
Parameters:
-
string stuff
|
the string in which you want to search for something. |
int OffSet
|
the offset where to start the search. |
-
Returns:
-
boolean true if the regular expression matched. false if not.
-
See also:
-
bool search(const string& stuff)
|
bool Pcre::search (
|
const string & stuff )
|
|
|
Do a search on the given string. This method does the actual search on the given string. -
Parameters:
-
string stuff
|
the string in which you want to search for something. |
-
Returns:
-
boolean true if the regular expression matched. false if not.
-
See also:
-
bool search(const string& stuff, int OffSet)
|
Member Data Documentation
|
true if the expression produced a match
Definition at line 114 of file pcre++.h. |
The documentation for this class was generated from the following file:
Generated at Fri Jan 4 03:57:04 2002 for PCRE++ by
1.2.6 written by Dimitri van Heesch,
© 1997-2001