edelib  2.1.0
Public Types | Public Member Functions | List of all members
Regex Class Reference

Regex class. More...

#include <edelib/Regex.h>

Public Types

typedef list< RegexMatchMatchVec

Public Member Functions

 Regex ()
 ~Regex ()
bool compile (const char *pattern, int m=0)
 operator bool (void) const
int match (const char *str, int match_mode, int start, int len, MatchVec *matches)
int match (const char *str, int match_mode=0, MatchVec *matches=0)
int split (const char *str, list< String > &ls, int match_mode=0)
const char * strerror (void) const

Detailed Description

Regex class.

Regex is pattern matching (aka. regular expression) class used to search certain substrings inside line or text. This class use Perl compatible expressions thanks to PCRE backend.

Before doing some matching, you must compile pattern first buy using compile() member.

Matching is done via match() member. It will return the number of matched substrings and (if given) set RegexMatch list with offsets. If fails, -1 will be returned. Here is the sample: that explains it:

* Regex r;
* r.compile("(de|br)mo");
* r.match("some demo string", 0, &mv);

Here, match() will return 2 and MatchVec list will have (5,4) and (5,2) values (where the first value is offset and the second substring length). This explains one important property inherited from PCRE: when grouped patterns are involved and they are found in string, MatchVec first element will be full matched string and substrings will follow.

Member Typedef Documentation

Shortcut for the list of RegexMatch

Constructor & Destructor Documentation

Regex ( )

Empty constructor

~Regex ( )

Clears all internal data

Member Function Documentation

bool compile ( const char *  pattern,
int  m = 0 

Compile pattern for matching. This must be called before match/search functions.

true if pattern compiled successfully, or false if not.
patternis matching pattern
mis RegexMode type
int match ( const char *  str,
int  match_mode,
int  start,
int  len,
MatchVec matches 

Search compiled pattern in str and return number of grouped matches. If pattern wasn't found or some error occured during search, returned value (depending on error) will be less than 0 (see PCRE documentation about returned values).

the number of grouped matches or value less than 0 in case of error
stris target string where compiled pattern is searched
match_modeis OR-ed RegexMatchMode value
startis starting position on string
lenis desired length where matching will occur; if given -1, full length will be searched
matchesis list of matching objects
int match ( const char *  str,
int  match_mode = 0,
MatchVec matches = 0 

The same as above match(), but matching will start from the beginning and full string length will be used

operator bool ( void  ) const

Validate if compile() was successfull. This is short way for checking compile() returned value, like:

* Regex r;
* r.compile(...);
* if(!r)
* // die
int split ( const char *  str,
list< String > &  ls,
int  match_mode = 0 

Split given str and put each of splitted items in list.

0 if pattern didn't find or size of the list
stris data to be splitted
lsis list where to put data
match_modeis OR-ed RegexMatchMode value
const char* strerror ( void  ) const

Return error in string form. Returned value points to static data and must not be modified or cleared

The documentation for this class was generated from the following file: