libtdepim

KRegExp3 Class Reference

#include <kregexp3.h>

Inherits TQRegExp.

Public Member Functions

 KRegExp3 (const TQString &pattern, bool caseSensitive=TRUE, bool wildcard=FALSE)
 
 KRegExp3 (const TQRegExp &rx)
 
 KRegExp3 (const KRegExp3 &rx)
 
TQString replace (const TQString &str, const TQString &replacementStr, int start=0, bool global=TRUE)
 

Detailed Description

A TQRegExp (TQt3.x) with a replace() method.

This class is simply there to provide a namespace for some nice enhancements of the mighty TQRegExp (TQt3 version) regular expression engine, namely the method replace(), which can be used to do search-and-replace like one is used to from perl or sed.

It "simply" adds the ability to define a replacement string which contains references to the captured substrings. The following constructs are understood, which can be freely mixed in the replacement string:

syntax

Back references in the replacement string are made using
(backslash-digit), where n is a single digit. With this mode of operation, only the first nine captured substrings can be referenced.

NOTE: Remember that C++ interprets the backslash in string constants, so you have to write a backslash as "\\".

syntax

Back references in the replacement string are made using $n (dollarsign-digit), where n is a single digit. With this mode of operation, only the first nine captured substrings can be referenced.

Additionally, Perl supports the syntax ${nn} (dollarSign-leftCurlyBrace-digits-rightCurlyBrace), where nn can be a multi-digit number.

In all modes, counting of captured substrings starts with 1 (one)! To reference the entire matched string, use $0, ${0} or \0.

Author
Marc Mutz mutz@.nosp@m.kde..nosp@m.org
See also
TQRegExp

Definition at line 79 of file kregexp3.h.

Member Function Documentation

◆ replace()

TQString KRegExp3::replace ( const TQString &  str,
const TQString &  replacementStr,
int  start = 0,
bool  global = TRUE 
)

Replaces each matching subpattern in str with replacementStr, inserting captured substrings for \n, $n and ${nn} as described in the class documentation.

Parameters
strThe source string.
replacementStrThe string which replaces matched substrings of str.
startStart position for the search. If start is negative, starts -(start) positions from the end of str.
globalIf TRUE, requests to replace all occurrences of the regexp with replacementStr; if FALSE, only the first occurrence will be replaced. Equivalent to the /g switch to perl's s/// operator.
Returns
The modified string.

Definition at line 40 of file kregexp3.cpp.


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