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 () | |
QRegExp & | operator= (const QRegExp &) |
QRegExp & | operator= (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 |
Private Attributes | |
QCString | rxstring |
uint * | rxdata |
int | error |
bool | cs |
bool | wc |
The QRegExp class provides pattern matching using regular expressions or wildcards.
QRegExp knows these regexp primitives:
c
matches the character 'c' .
matches any character ^
matches start of input $
matches end of input []
matches a defined set of characters - see below. a*
matches a sequence of zero or more a's a+
matches a sequence of one or more a's a?
matches an optional a
escape code for matching special characters such as \, [, *, +, . etc.
matches the TAB character (9)
matches newline (10)
matches return (13)
matches a white space (defined as any character for which QChar::isSpace() returns TRUE. This includes at least ASCII characters 9 (TAB), 10 (LF), 11 (VT), 12(FF), 13 (CR) and 32 (Space)).
matches a digit (defined as any character for which QChar::isDigit() returns TRUE. This includes at least ASCII characters '0'-'9').
matches the character with unicode point U1f6b (hexadecimal 1f6b). will match the ASCII/Latin1 character 0x12 (18 decimal, 12 hexadecimal). \022
matches the ASCII/Latin1 character 022 (18 decimal, 22 octal). In wildcard mode, it only knows four primitives:
c
matches the character 'c' ?
matches any character *
matches any sequence of characters []
matches a defined set of characters - see below. 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:
^
When placed first in the list, changes the character set to match any character not in the list. To include the character '^' itself in the set, escape it or place it anywhere but first. -
Defines a range of characters. To include the character '-' itself in the set, escape it or place it last. ]
Ends the character set definition. To include the character ']' itself in the set, escape it or place it first (but after the negation operator '^', if present) Thus, [a-zA-Z0-9.] matches upper and lower case ASCII letters, digits and dot; and [^] matches everything except white space.
QRegExp::QRegExp | ( | ) |
Constructs an empty regular expression.
Definition at line 174 of file qregexp.cpp.
Constructs a regular expression.
Definition at line 195 of file qregexp.cpp.
QRegExp::QRegExp | ( | const QRegExp & | r | ) |
Constructs a regular expression which is a copy of r.
Definition at line 209 of file qregexp.cpp.
QRegExp::~QRegExp | ( | ) |
Destructs the regular expression and cleans up its internal data.
Definition at line 222 of file qregexp.cpp.
|
inline |
Returns TRUE if case sensitivity is enabled, otherwise FALSE. The default is TRUE.
Definition at line 63 of file qregexp.h.
|
protected |
Definition at line 914 of file qregexp.cpp.
|
inline |
Attempts to match in str, starting from position index. Returns the position of the match, or -1 if there was no match.
Definition at line 76 of file qregexp.h.
|
inline |
|
inline |
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.
Definition at line 649 of file qregexp.cpp.
Returns TRUE if this regexp is not equal to r.
Definition at line 57 of file qregexp.h.
Copies the regexp r and returns a reference to this regexp. The case sensitivity and wildcard options are copied, as well.
Definition at line 233 of file qregexp.cpp.
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.
Definition at line 250 of file qregexp.cpp.
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.
Definition at line 265 of file qregexp.cpp.
|
inline |
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()
Definition at line 335 of file qregexp.cpp.
|
inline |
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).
Definition at line 310 of file qregexp.cpp.
|
inline |
Returns TRUE if wildcard mode is on, otherwise FALSE.
Definition at line 66 of file qregexp.h.