1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Qt Toolkit - QRegExp Class</title><style type="text/css"><!--
h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }body { background: white; color: black; }
--></style>
</head><body bgcolor="#ffffff">
<table width="100%">
<tr><td><a href="index.html">
<img width="100" height="100" src="qtlogo.png"
alt="Home" border="0"><img width="100"
height="100" src="face.png" alt="Home" border="0">
</a><td valign=top><div align=right><img src="dochead.png" width="472" height="27"><br>
<a href="classes.html"><b>Classes</b></a>
-<a href="annotated.html">Annotated</a>
- <a href="hierarchy.html">Tree</a>
-<a href="functions.html">Functions</a>
-<a href="index.html">Home</a>
-<a href="topicals.html"><b>Structure</b></a>
</div>
</table>
<h1 align=center>QRegExp Class Reference</h1><br clear="all">
<p>
The QRegExp class provides pattern matching using regular expressions or wildcards.
<a href="#details">More...</a>
<p>
<code>#include <<a href="qregexp-h.html">qregexp.h</a>></code>
<p><a href="qregexp-members.html">List of all member functions.</a>
<h2>Public Members</h2>
<ul>
<li><div class="fn"><a href="#ef4171"><b>QRegExp</b></a>()</div>
<li><div class="fn"><a href="#8c3756"><b>QRegExp</b></a>(constQString&, boolcaseSensitive=TRUE, boolwildcard=FALSE)</div>
<li><div class="fn"><a href="#610fed"><b>QRegExp</b></a>(constQRegExp&)</div>
<li><div class="fn"><a href="#52f317"><b>~QRegExp</b></a>()</div>
<li><div class="fn">QRegExp&<a href="#6a9698"><b>operator=</b></a>(constQRegExp&)</div>
<li><div class="fn">QRegExp&operator=(constQString&pattern)<em>(obsolete)</em></div>
<li><div class="fn">bool<a href="#a57bd9"><b>operator==</b></a>(constQRegExp&)const</div>
<li><div class="fn">bool<a href="#f1215b"><b>operator!=</b></a>(constQRegExp&r)const</div>
<li><div class="fn">bool<a href="#a3811c"><b>isEmpty</b></a>()const</div>
<li><div class="fn">bool<a href="#1ed92e"><b>isValid</b></a>()const</div>
<li><div class="fn">bool<a href="#92bf0e"><b>caseSensitive</b></a>()const</div>
<li><div class="fn">void<a href="#2f6a93"><b>setCaseSensitive</b></a>(bool)</div>
<li><div class="fn">bool<a href="#f5534a"><b>wildcard</b></a>()const</div>
<li><div class="fn">void<a href="#720b12"><b>setWildcard</b></a>(bool)</div>
<li><div class="fn">QString<a href="#cbfdcd"><b>pattern</b></a>()const</div>
<li><div class="fn">void<a href="#2c9170"><b>setPattern</b></a>(constQString&pattern)</div>
<li><div class="fn">int<a href="#e1927d"><b>match</b></a>(constQString&str, intindex=0, int*len=0, boolindexIsStart=TRUE)const</div>
<li><div class="fn">int<a href="#0c3ddc"><b>find</b></a>(constQString&str, intindex)</div>
</ul>
<h2>Protected Members</h2>
<ul>
<li><div class="fn">void<b>compile</b>()(internal)</div>
<li><div class="fn">constQChar*<b>matchstr</b>(uint*, constQChar*, uint, constQChar*)const(internal)</div>
</ul>
<hr><h2><a name="details"></a>Detailed Description</h2>
The QRegExp class provides pattern matching using regular expressions or wildcards.
<p>
QRegExp knows these regexp primitives:
<ul plain>
<li><dfn>c</dfn> matches the character 'c'
<li><dfn>.</dfn> matches any character
<li><dfn>^</dfn> matches start of input
<li><dfn>$</dfn> matches end of input
<li><dfn>[]</dfn> matches a defined set of characters - see below.
<li><dfn>a*</dfn> matches a sequence of zero or more a's
<li><dfn>a+</dfn> matches a sequence of one or more a's
<li><dfn>a?</dfn> matches an optional a
<li><dfn>\c</dfn> escape code for matching special characters such
as \, [, *, +, . etc.
<li><dfn>\t</dfn> matches the TAB character (9)
<li><dfn>\<a href="n.html">n</a></dfn> matches newline (10)
<li><dfn>\r</dfn> matches return (13)
<li><dfn>\s</dfn> matches a white space (defined as any character
for which <a href="qchar.html#9744c0">QChar::isSpace</a>() returns TRUE. This includes at least
ASCII characters 9 (TAB), 10 (LF), 11 (VT), 12(FF), 13 (CR) and 32
(Space)).
<li><dfn>\d</dfn> matches a digit (defined as any character for
which <a href="qchar.html#2f74af">QChar::isDigit</a>() returns TRUE. This includes at least ASCII
characters '0'-'9').
<li><dfn>\x1f6b</dfn> matches the character with unicode point U1f6b
(hexadecimal 1f6b). \x0012 will match the ASCII/Latin1 character
0x12 (18 decimal, 12 hexadecimal).
<li><dfn>\022</dfn> matches the ASCII/Latin1 character 022 (18
decimal, 22 octal).
</ul>
<p>In wildcard mode, it only knows four primitives:
<ul plain>
<li><dfn>c</dfn> matches the character 'c'
<li><dfn>?</dfn> matches any character
<li><dfn>*</dfn> matches any sequence of characters
<li><dfn>[]</dfn> matches a defined set of characters - see below.
</ul>
<p>QRegExp supports Unicode both in the pattern strings and in the
strings to be matched.
<p>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 "\.".
<p>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:
<ul plain>
<li><dfn>^</dfn> When placed first in the list, changes the
character set to match any character <em>not</em> in the list. To include
the character '^' itself in the set, escape it or place it anywhere
but first.
<li><dfn>-</dfn> Defines a range of characters. To include the
character '-' itself in the set, escape it or place it last.
<li><dfn>]</dfn> 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)
</ul>
Thus, [a-zA-Z0-9.] matches upper and lower case ASCII letters,
digits and dot; and [^\s] matches everything except white space.
<p>\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.
<p>Bugs and limitations:
<ul>
<li>Case insensitive matching is not supported for non-ASCII/Latin1
(non-8bit) characters. Any character with a non-zero <a href="qchar.html">QChar</a>.row() is
matched case sensitively even if the QRegExp is in case insensitive
mode.
</ul>
<p>Examples:
<a href="qmag-qmag-cpp.html#QRegExp">qmag/qmag.cpp</a>
<hr><h2>Member Function Documentation</h2>
<h3 class="fn"><a name="ef4171"></a>QRegExp::QRegExp()</h3>
<p>Constructs an empty regular expression.
<h3 class="fn"><a name="8c3756"></a>QRegExp::QRegExp(const<a href="qstring.html">QString</a>&pattern, boolcaseSensitive=TRUE, boolwildcard=FALSE)</h3>
<p>Constructs a regular expression.
<p>Arguments:
<ul>
<li><em>pattern</em> is the regular expression pattern string.
<li><em>caseSensitive</em> specifies whether or not to use case sensitive
matching.
<li><em>wildcard</em> specifies whether the pattern string should be used for
wildcard matching (also called globbing expression), normally used for
matching file names.
</ul>
<p>See also <a href="#720b12">setWildcard</a>().
<h3 class="fn"><a name="610fed"></a>QRegExp::QRegExp(constQRegExp&r)</h3>
<p>Constructs a regular expression which is a copy of <em>r.</em>
<p>See also <a href="#50f35e">operator=</a>(const and <a href="qregexp.html">QRegExp</a>&).
<h3 class="fn"><a name="52f317"></a>QRegExp::~QRegExp()</h3>
<p>Destructs the regular expression and cleans up its internal data.
<h3 class="fn">bool<a name="92bf0e"></a>QRegExp::caseSensitive()const</h3>
<p>Returns TRUE if case sensitivity is enabled, otherwise FALSE. The
default is TRUE.
<p>See also <a href="#2f6a93">setCaseSensitive</a>().
<h3 class="fn">int<a name="0c3ddc"></a>QRegExp::find(const<a href="qstring.html">QString</a>&str, intindex)</h3>
<p>Attempts to match in <em>str,</em> starting from position <em>index.</em>
Returns the position of the match, or -1 if there was no match.
<p>See also <a href="#e1927d">match</a>().
<h3 class="fn">bool<a name="a3811c"></a>QRegExp::isEmpty()const</h3>
<p>Returns TRUE if the regexp is empty.
<h3 class="fn">bool<a name="1ed92e"></a>QRegExp::isValid()const</h3>
<p>Returns TRUE if the regexp is valid, or FALSE if it is invalid.
<p>The pattern "[a-z" is an example of an invalid pattern, since it lacks a
closing bracket.
<h3 class="fn">int<a name="e1927d"></a>QRegExp::match(const<a href="qstring.html">QString</a>&str, intindex=0, int*len=0, boolindexIsStart=TRUE)const</h3>
<p>Attempts to match in <em>str,</em> starting from position <em>index.</em>
Returns the position of the match, or -1 if there was no match.
<p>If <em>len</em> is not a null pointer, the length of the match is stored in
<em>*len.</em>
<p>If <em>indexIsStart</em> is TRUE (the default), the position <em>index</em> in
the string will match the start-of-input primitive (^) in the
regexp, if present. Otherwise, position 0 in <em>str</em> will match.
<p>Example:
<pre> <a href="qregexp.html">QRegExp</a> r("[0-9]*\\.[0-9]+"); // matches floating point
int len;
r.<a href="#e1927d">match</a>("pi = 3.1416", 0, &len); // returns 5, len == 6
</pre>
<p>\note In Qt 3.0, this function will be replaced by <a href="#0c3ddc">find</a>().
<p>Examples:
<a href="qmag-qmag-cpp.html#match">qmag/qmag.cpp</a>
<h3 class="fn">bool<a name="f1215b"></a>QRegExp::operator!=(constQRegExp&r)const</h3>
<p>Returns TRUE if this regexp is <em>not</em> equal to <em>r.</em>
<p>See also <a href="#a57bd9">operator==</a>().
<h3 class="fn">QRegExp&<a name="50f35e"></a>QRegExp::operator=(const<a href="qstring.html">QString</a>&pattern)</h3>
<p><b>This function is obsolete.</b> It is provided to keep old source working, and will probably be removed in a future version of Qt. We strongly advise against using it in new code.<p>
Consider using <a href="#2c9170">setPattern</a>() instead of this method.
<p>Sets the pattern string to <em>pattern</em> and returns a reference to this regexp.
The case sensitivity or wildcard options do not change.
<h3 class="fn">QRegExp&<a name="6a9698"></a>QRegExp::operator=(constQRegExp&r)</h3>
<p>Copies the regexp <em>r</em> and returns a reference to this regexp.
The case sensitivity and wildcard options are copied, as well.
<h3 class="fn">bool<a name="a57bd9"></a>QRegExp::operator==(constQRegExp&r)const</h3>
<p>Returns TRUE if this regexp is equal to <em>r.</em>
<p>Two regexp objects are equal if they have equal pattern strings,
case sensitivity options and wildcard options.
<h3 class="fn"><a href="qstring.html">QString</a><a name="cbfdcd"></a>QRegExp::pattern()const</h3>
<p>Returns the pattern string of the regexp.
<h3 class="fn">void<a name="2f6a93"></a>QRegExp::setCaseSensitive(boolenable)</h3>
<p>Enables or disables case sensitive matching.
<p>In case sensitive mode, "a.e" matches "axe" but not "Axe".
<p>See also: <a href="#92bf0e">caseSensitive</a>().
<h3 class="fn">void<a name="2c9170"></a>QRegExp::setPattern(const<a href="qstring.html">QString</a>&pattern)</h3>
<p>Sets the pattern string to <em>pattern</em> and returns a reference to this regexp.
The case sensitivity or wildcard options do not change.
<h3 class="fn">void<a name="720b12"></a>QRegExp::setWildcard(boolwildcard)</h3>
<p>Sets the wildcard option for the regular expression. The default
is FALSE.
<p>Setting <em>wildcard</em> to TRUE makes it convenient to match filenames
instead of plain text.
<p>For example, "qr*.cpp" matches the string "qregexp.cpp" in wildcard mode,
but not "qicpp" (which would be matched in normal mode).
<p>See also <a href="#f5534a">wildcard</a>().
<h3 class="fn">bool<a name="f5534a"></a>QRegExp::wildcard()const</h3>
<p>Returns TRUE if wildcard mode is on, otherwise FALSE.
<p>See also <a href="#720b12">setWildcard</a>().
<h3 class="fn">void<a name="8fc09a"></a>QRegExp::compile() <code>[protected]</code></h3>
<p>For internal use only.
<h3 class="fn">const<a href="qchar.html">QChar</a>*<a name="fe61fb"></a>QRegExp::matchstr(uint*rxd, const<a href="qchar.html">QChar</a>*str, uintstrlength, const<a href="qchar.html">QChar</a>*bol)const <code>[protected]</code></h3>
<p>For internal use only.
<hr><p>
Search the documentation, FAQ, qt-interest archive and more (uses
<a href="http://www.trolltech.com">www.trolltech.com</a>):<br>
<form method=post action="http://www.trolltech.com/search.cgi">
<input type=hidden name="version" value="2.3.1"><nobr>
<input size="50" name="search"><input type=submit value="Search">
</nobr></form><hr><p>
This file is part of the <a href="index.html">Qt toolkit</a>,
copyright © 1995-2000
<a href="http://www.trolltech.com">Trolltech</a>, all rights reserved.<p><address><hr><div align="center">
<table width="100%" cellspacing="0" border="0"><tr>
<td>Copyright 2000 Trolltech<td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a>
<td align="right"><div align="right">Qt version 2.3.1</div>
</table></div></address></body></html>
|