Qt logo

QRegExp Class Reference


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

#include <qregexp.h>

List of all member functions.

Public Members

Protected Members


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 the C++ preprocessor processes \ characters. So in order to match e.g. a "." character, you must write "\\." in C++ source, not "\.".

Bugs and limitations:

Examples: qmag/qmag.cpp


Member Function Documentation

QRegExp::QRegExp()

Constructs an empty regular expression.

QRegExp::QRegExp(constQString&pattern, boolcaseSensitive=TRUE, boolwildcard=FALSE)

Constructs a regular expression.

Arguments:

See also: setWildcard().

QRegExp::QRegExp(constQRegExp&r)

Constructs a regular expression which is a copy of r.

See also: operator=(const and QRegExp&).

QRegExp::~QRegExp()

Destroys the regular expression and cleans up its internal data.

boolQRegExp::caseSensitive()const

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

See also: setCaseSensitive().

voidQRegExp::compile() [protected]

For internal use only.

boolQRegExp::isEmpty()const

Returns TRUE if the regexp is empty.

boolQRegExp::isValid()const

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.

intQRegExp::match(constQString&str, intindex=0, int*len=0, boolindexIsStart=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

Examples: qmag/qmag.cpp

constQChar*QRegExp::matchstr(uint*rxd, constQChar*str, uintstrlength, constQChar*bol)const [protected]

For internal use only.

boolQRegExp::operator!=(constQRegExp&r)const

Returns TRUE if this regexp is not equal to r.

See also: operator==().

QRegExp&QRegExp::operator=(constQString&pattern)

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

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

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

boolQRegExp::operator==(constQRegExp&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.

QStringQRegExp::pattern()const

Returns the pattern string of the regexp.

voidQRegExp::setCaseSensitive(boolenable)

Enables or disables case sensitive matching.

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

See also: caseSensitive().

voidQRegExp::setWildcard(boolwildcard)

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 will be matched in normal mode).

See also: wildcard().

boolQRegExp::wildcard()const

Returns TRUE if wildcard mode is on, otherwise FALSE.

See also: setWildcard().


Search the documentation, FAQ, qt-interest archive and more (uses www.troll.no):


This file is part of the Qt toolkit, copyright © 1995-99 Troll Tech, all rights reserved.


Copyright 1999 Troll TechTrademarks
Qt version 2.0.2