Main Page   Class Hierarchy   Alphabetical List   Compound List   Compound Members  

util::Regex Class Reference

#include <Regex.h>

List of all members.


Detailed Description

Regex is a class for easy implementation of regular expression search and replace operations.

It provides support for POSIX extended regular expressions in both case sensitive and case insensitive modes.


Static Public Methods

int find (const std::string &haystack, const std::string &needle, bool ignoreCase=false, int startIndex=0)
 Find needle in haystack.

std::string replace (const std::string &haystack, const std::string &needle, const std::string &replacement, bool ignoreCase=false, int max=-1)
 Replace needle with replacement in haystack.

void tokenize (const std::string &str, const std::string &regex, List< std::string > &result, bool ignoreCase=false, int max=-1)
 Split a string by a regular expression.

List< std::string > tokenize (const std::string &str, const std::string &regex, bool ignoreCase=false, int max=-1)
 Split a string by a regular expression.


Member Function Documentation

int util::Regex::find const std::string &    haystack,
const std::string &    needle,
bool    ignoreCase = false,
int    startIndex = 0
[static]
 

Find needle in haystack.

Parameters:
haystack  any string
needle  a POSIX extended regular expression
startIndex  start search at this point
ignoreCase  if true, the search is case-insensitive
Returns:
the index of the first match, or -1 if not found

string util::Regex::replace const std::string &    haystack,
const std::string &    needle,
const std::string &    replacement,
bool    ignoreCase = false,
int    max = -1
[static]
 

Replace needle with replacement in haystack.

Needle is a regular expression complying to the POSIX extended regex specification. Replacement may contain escaped sequences '\0' to '\9' that are replaced with the respective substring matches. '\0' means the whole match, '\1' means the first substring etc.

Example:

 //replace "_text_" with "{text}" in str
 str = replace(str,"_(.+)_","{\1}");
 //replace "http://www.foo.com/" with [www.foo.com]
 str = replace(str,"http://(.+)([[:blank:][:punct:]])","[\1]\2");
 //replace "email@host.com" with "mailto:email@host.com"
 str = replace(str,"[[:alnum:].-]+@[[:alnum:].-]+[a-z]","mailto:\0");
 
Parameters:
haystack  search in this string
needle  search for this regex
replacement  replace each match with this
max  replace at most this many occurrences (<1 for all)
ignoreCase  if true, the search is case-insensitive
Returns:
a new string with regex matches replaced

List<std::string> util::Regex::tokenize const std::string &    str,
const std::string &    regex,
bool    ignoreCase = false,
int    max = -1
[inline, static]
 

Split a string by a regular expression.

Parameters:
str  the string to be split
regex  a regular expression that matches item separators
max  maximum number of pieces
Returns:
the pieces in a list

void util::Regex::tokenize const std::string &    str,
const std::string &    regex,
List< std::string > &    result,
bool    ignoreCase = false,
int    max = -1
[static]
 

Split a string by a regular expression.

Parameters:
str  the string to be split
regex  a regular expression that matches item separators
result  store the resulting pieces in this list
max  maximum number of pieces


The documentation for this class was generated from the following files:
Documentation generated on 11.09.2003 with Doxygen.
The documentation is copyrighted material.
Copyright © Topi Mäenpää 2003. All rights reserved.