ISLEman
Public Member Functions | Protected Member Functions | List of all members
QRegExp Class Reference

The QRegExp class provides pattern matching using regular expressions or wildcards. More...

#include <qregexp.h>

Public Member Functions

 QRegExp ()
 
 QRegExp (const QCString &, bool caseSensitive=TRUE, bool wildcard=FALSE)
 
 QRegExp (const QRegExp &)
 
 ~QRegExp ()
 
QRegExpoperator= (const QRegExp &)
 
QRegExpoperator= (const QCString &pattern)
 
bool operator== (const QRegExp &) const
 
bool operator!= (const QRegExp &r) const
 
bool isEmpty () const
 
bool isValid () const
 
bool caseSensitive () const
 
void setCaseSensitive (bool)
 
bool wildcard () const
 
void setWildcard (bool)
 
QCString pattern () const
 
void setPattern (const QCString &pattern)
 
int match (const QCString &str, int index=0, int *len=0, bool indexIsStart=TRUE) const
 
int find (const QCString &str, int index)
 

Protected Member Functions

void compile ()
 
const char * matchstr (uint *, const char *, uint, const char *) const
 

Detailed Description

The QRegExp class provides pattern matching using regular expressions or wildcards.

QRegExp knows these regexp primitives:

In wildcard mode, it only knows four primitives:

QRegExp supports Unicode both in the pattern strings and in the strings to be matched.

When writing regular expressions in C++ code, remember that C++ processes \ characters. So in order to match e.g. a "." character, you must write "\\." in C++ source, not "\.".

A character set matches a defined set of characters. For example, [BSD] matches any of 'B', 'D' and 'S'. Within a character set, the special characters '.', '*', '?', '^', '$', '+' and '[' lose their special meanings. The following special characters apply:

Thus, [a-zA-Z0-9.] matches upper and lower case ASCII letters, digits and dot; and [^] matches everything except white space.

Bug:
Case insensitive matching is not supported for non-ASCII/Latin1 (non-8bit) characters. Any character with a non-zero QChar.row() is matched case sensitively even if the QRegExp is in case insensitive mode.
Note
In Qt 3.0, the language of regular expressions will contain five more special characters, namely '(', ')', '{', '|' and '}'. To ease porting, it's a good idea to escape these characters with a backslash in all the regular expressions you'll write from now on.

Constructor & Destructor Documentation

§ QRegExp() [1/3]

QRegExp::QRegExp ( )

Constructs an empty regular expression.

§ QRegExp() [2/3]

QRegExp::QRegExp ( const QCString pattern,
bool  caseSensitive = TRUE,
bool  wildcard = FALSE 
)

Constructs a regular expression.

  • pattern is the regular expression pattern string.
  • caseSensitive specifies whether or not to use case sensitive matching.
  • wildcard specifies whether the pattern string should be used for wildcard matching (also called globbing expression), normally used for matching file names.
See also
setWildcard()

§ QRegExp() [3/3]

QRegExp::QRegExp ( const QRegExp r)

Constructs a regular expression which is a copy of r.

See also
operator=(const QRegExp&)

§ ~QRegExp()

QRegExp::~QRegExp ( )

Destructs the regular expression and cleans up its internal data.

Member Function Documentation

§ caseSensitive()

bool QRegExp::caseSensitive ( ) const
inline

Returns TRUE if case sensitivity is enabled, otherwise FALSE. The default is TRUE.

See also
setCaseSensitive()

§ find()

int QRegExp::find ( const QCString str,
int  index 
)
inline

Attempts to match in str, starting from position index. Returns the position of the match, or -1 if there was no match.

See also
match()

§ isEmpty()

bool QRegExp::isEmpty ( ) const
inline

Returns TRUE if the regexp is empty.

§ isValid()

bool QRegExp::isValid ( ) const
inline

Returns TRUE if the regexp is valid, or FALSE if it is invalid.

The pattern "[a-z" is an example of an invalid pattern, since it lacks a closing bracket.

§ match()

int QRegExp::match ( const QCString str,
int  index = 0,
int *  len = 0,
bool  indexIsStart = TRUE 
) const

Attempts to match in str, starting from position index. Returns the position of the match, or -1 if there was no match.

If len is not a null pointer, the length of the match is stored in *len.

If indexIsStart is TRUE (the default), the position index in the string will match the start-of-input primitive (^) in the regexp, if present. Otherwise, position 0 in str will match.

Example:

QRegExp r("[0-9]*\\.[0-9]+"); // matches floating point
int len;
r.match("pi = 3.1416", 0, &len); // returns 5, len == 6
Note
In Qt 3.0, this function will be replaced by find().

§ operator!=()

bool QRegExp::operator!= ( const QRegExp r) const
inline

Returns TRUE if this regexp is not equal to r.

See also
operator==()

§ operator=() [1/2]

QRegExp & QRegExp::operator= ( const QRegExp r)

Copies the regexp r and returns a reference to this regexp. The case sensitivity and wildcard options are copied, as well.

§ operator=() [2/2]

QRegExp & QRegExp::operator= ( const QCString pattern)

Consider using setPattern() instead of this method.

Sets the pattern string to pattern and returns a reference to this regexp. The case sensitivity or wildcard options do not change.

§ operator==()

bool QRegExp::operator== ( const QRegExp r) const

Returns TRUE if this regexp is equal to r.

Two regexp objects are equal if they have equal pattern strings, case sensitivity options and wildcard options.

§ pattern()

QCString QRegExp::pattern ( ) const
inline

Returns the pattern string of the regexp.

§ setCaseSensitive()

void QRegExp::setCaseSensitive ( bool  enable)

Enables or disables case sensitive matching.

In case sensitive mode, "a.e" matches "axe" but not "Axe".

See also: caseSensitive()

§ setPattern()

void QRegExp::setPattern ( const QCString pattern)
inline

Sets the pattern string to pattern and returns a reference to this regexp. The case sensitivity or wildcard options do not change.

§ setWildcard()

void QRegExp::setWildcard ( bool  wildcard)

Sets the wildcard option for the regular expression. The default is FALSE.

Setting wildcard to TRUE makes it convenient to match filenames instead of plain text.

For example, "qr*.cpp" matches the string "qregexp.cpp" in wildcard mode, but not "qicpp" (which would be matched in normal mode).

See also
wildcard()

§ wildcard()

bool QRegExp::wildcard ( ) const
inline

Returns TRUE if wildcard mode is on, otherwise FALSE.

See also
setWildcard().

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