⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qregexp.3qt

📁 linux下GUI编程工具qt的在线连接帮助手册
💻 3QT
📖 第 1 页 / 共 3 页
字号:
.br        pos = rx.search( str, pos );.br        if ( pos > -1 ) {.br            list += rx.cap( 1 );.br            pos  += rx.matchedLength();.br        }.br    }.br    // list contains "12", "14", "99", "231", "7".br.fi.PPSee also capturedTexts(), pos(), exactMatch(), search() and searchRev()..SH "QStringList QRegExp::capturedTexts ()"Returns a list of the captured text strings..PPThe first string in the list is the entire matched string. Each subsequent list element contains a string that matched a (capturing) subexpression of the regexp..PPFor example:.PP.nf.br    QRegExp rx( "(\\\\d+)(\\\\s*)(cm|inch(es)?)" );.br    int pos = rx.search( "Length: 36 inches" );.br    QStringList list = rx.capturedTexts();.br    // list is now ( "36 inches", "36", " ", "inches", "es" ).br.fi.PPThe above example also captures elements that may be present but which we have no interest in. This problem can be solved by using non-capturing parentheses:.PP.nf.br    QRegExp rx( "(\\\\d+)(?:\\\\s*)(cm|inch(?:es)?)" );.br    int pos = rx.search( "Length: 36 inches" );.br    QStringList list = rx.capturedTexts();.br    // list is now ( "36 inches", "36", "inches" ).br.fi.PPSome regexps can match an indeterminate number of times. For example if the input string is "Offsets: 12 14 99 231 7" and the regexp, \fCrx\fR, is \fB(&#92;d+)+\fR, we would hope to get a list of all the numbers matched. However, after calling \fCrx.search(str)\fR, capturedTexts() will return the list ( "12"," 12" ), i.e. the entire match was "12" and the first subexpression matched was "12". The correct approach is to use cap() in a loop..PPThe order of elements in the string list is as follows. The first element is the entire matching string. Each subsequent element corresponds to the next capturing open left parentheses. Thus capturedTexts()[1] is the text of the first capturing parentheses, capturedTexts()[2] is the text of the second and so on (corresponding to $1, $2, etc., in some other regexp languages)..PPSee also cap(), pos(), exactMatch(), search() and searchRev()..SH "bool QRegExp::caseSensitive () const"Returns TRUE if case sensitivity is enabled, otherwise FALSE. The default is TRUE..PPSee also setCaseSensitive()..SH "bool QRegExp::exactMatch ( const QString & str ) const"Returns TRUE if \fIstr\fR is matched exactly by this regular expression otherwise it returns FALSE. You can determine how much of the string was matched by calling matchedLength()..PPFor a given regexp string, R, exactMatch("R") is the equivalent of search("^R$") since exactMatch() effectively encloses the regexp in the start of string and end of string anchors, except that it sets matchedLength() differently..PPFor example, if the regular expression is \fBblue\fR, then exactMatch() returns TRUE only for input \fCblue\fR. For inputs \fCbluebell\fR, \fCblutak\fR and \fClightblue\fR, exactMatch() returns FALSE and matchedLength() will return 4, 3 and 0 respectively..PPAlthough const, this function sets matchedLength(), capturedTexts() and pos()..PPSee also search(), searchRev() and QRegExpValidator..SH "bool QRegExp::isEmpty () const"Returns TRUE if the pattern string is empty, otherwise FALSE..PPIf you call exactMatch() with an empty pattern on an empty string it will return TRUE; otherwise it returns FALSE since it operates over the whole string. If you call search() with an empty pattern on \fIany\fR string it will return the start position (0 by default) since it will match at the start position, because the empty pattern matches the 'emptiness' at the start of the string, and the length of the match returned by matchedLength() will be 0..PPSee QString::isEmpty()..SH "bool QRegExp::isValid () const"Returns TRUE if the regular expression is valid, or FALSE if it's invalid. An invalid regular expression never matches..PPThe pattern \fB[a-z\fR is an example of an invalid pattern, since it lacks a closing square bracket..PPNote that the validity of a regexp may also depend on the setting of the wildcard flag, for example \fB*.html\fR is a valid wildcard regexp but an invalid full regexp..SH "int QRegExp::match ( const QString & str, int index = 0, int * len = 0, bool indexIsStart = TRUE ) const"\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code..PPAttempts to match in \fIstr\fR, starting from position \fIindex\fR. Returns the position of the match, or -1 if there was no match..PPThe length of the match is stored in \fI*len\fR, unless \fIlen\fR is a null pointer..PPIf \fIindexIsStart\fR is TRUE (the default), the position \fIindex\fR in the string will match the start of string anchor, \fB^\fR, in the regexp, if present. Otherwise, position 0 in \fIstr\fR will match..PPUse search() and matchedLength() instead of this function..PPIf you really need the \fIindexIsStart\fR functionality, try this:.PP.nf.br    QRegExp rx( "some pattern" );.br    int pos = rx.search( str.mid(index) );.br    if ( pos >= 0 ).br        pos += index;.br    int len = rx.matchedLength();.br.fi.PPWhere performance is important, you can replace \fCstr.mid(index)\fR by \fCQConstString(str.unicode() + index, str.length() - index).string()\fR, which avoids copying the character data..PPSee also QString::mid() and QConstString..PPExample: qmag/qmag.cpp..SH "int QRegExp::matchedLength () const"Returns the length of the last matched string, or -1 if there was no match..PPSee also exactMatch(), search() and searchRev()..SH "bool QRegExp::minimal () const"Returns TRUE if minimal (non-greedy) matching is enabled, otherwise returns FALSE..PPSee also setMinimal()..SH "bool QRegExp::operator!= ( const QRegExp & rx ) const"Returns TRUE if this regular expression is not equal to \fIrx\fR, otherwise FALSE..PPSee also operator==()..SH "QRegExp & QRegExp::operator= ( const QRegExp & rx )"Copies the regular expression \fIrx\fR and returns a reference to the copy. The case sensitivity, wildcard and minimal matching options are copied as well..SH "bool QRegExp::operator== ( const QRegExp & rx ) const"Returns TRUE if this regular expression is equal to \fIrx\fR, otherwise returns FALSE..PPTwo QRegExp objects are equal if they have the same pattern strings and the same settings for case sensitivity, wildcard and minimal matching..SH "QString QRegExp::pattern () const"Returns the pattern string of the regular expression. The pattern has either regular expression syntax or wildcard syntax, depending on wildcard()..PPSee also setPattern()..SH "int QRegExp::pos ( int nth = 0 )"Returns the position of the \fInth\fR captured text in the searched string. If \fInth\fR is 0 (the default), pos() returns the position of the whole match..PPExample:.PP.nf.br    QRegExp rx( "/([a-z]+)/([a-z]+)" );.br    rx.search( "Output /dev/null" );    // returns 7 (position of /dev/null).br    rx.pos( 0 );                        // returns 7 (position of /dev/null).br    rx.pos( 1 );                        // returns 8 (position of dev).br    rx.pos( 2 );                        // returns 12 (position of null).br.fi.PPFor zero-length matches, pos() always returns -1. (For example, if cap(4) would return an empty string, pos(4) returns -1.) This is due to an implementation tradeoff..PPSee also capturedTexts(), exactMatch(), search() and searchRev()..SH "int QRegExp::search ( const QString & str, int start = 0 ) const"Attempts to find a match in \fIstr\fR from position \fIstart\fR (0 by default). If \fIstart\fR is -1, the search starts at the last character; if -2, at the next to last character; etc..PPReturns the position of the first match, or -1 if there was no match..PPYou might prefer to use QString::find(), QString::contains() or even QStringList::grep(). To replace matches use QString::replace()..PPExample:.PP.nf.br    QString str = "offsets: 1.23 .50 71.00 6.00";.br    QRegExp rx( "\\\\d*\\\\.\\\\d+" );    // primitive floating point matching.br    int count = 0;.br    int pos = 0;.br    while ( pos >= 0 ) {.br        pos = rx.search( str, pos );.br        count++;.br    }.br    // pos will be 9, 14, 18 and finally 24; count will end up as 4.br.fi.PPAlthough const, this function sets matchedLength(), capturedTexts() and pos()..PPSee also searchRev() and exactMatch()..SH "int QRegExp::searchRev ( const QString & str, int start = -1 ) const"Attempts to find a match backwards in \fIstr\fR from position \fIstart\fR. If \fIstart\fR is -1 (the default), the search starts at the last character; if -2, at the next to last character; etc..PPReturns the position of the first match, or -1 if there was no match..PPAlthough const, this function sets matchedLength(), capturedTexts() and pos()..PP\fBWarning:\fR Searching backwards is much slower than searching forwards..PPSee also search() and exactMatch()..SH "void QRegExp::setCaseSensitive ( bool sensitive )"Sets case sensitive matching to \fIsensitive\fR..PPIf \fIsensitive\fR is TRUE, \fB&#92;.txt$\fR matches \fCreadme.txt\fR but not \fCREADME.TXT\fR..PPSee also caseSensitive()..SH "void QRegExp::setMinimal ( bool minimal )"Enables or disables minimal matching. If \fIminimal\fR is FALSE, matching is greedy (maximal) which is the default..PPFor example, suppose we have the input string "We must be <b>bold</b>, very <b>bold</b>!" and the pattern \fB<b>.*</b>\fR. With the default greedy (maximal) matching, the match is" We must be <u><b>bold</b>, very <b>bold</b></u>!". But with minimal (non-greedy) matching the first match is:" We must be <u><b>bold</b></u>, very <b>bold</b>!" and the second match is" We must be <b>bold</b>, very <u><b>bold</b></u>!". In practice we might use the pattern \fB<b>[^<]+</b>\fR, although this will still fail for nested tags..PPSee also minimal()..SH "void QRegExp::setPattern ( const QString & pattern )"Sets the pattern string to \fIpattern\fR and returns a reference to this regular expression. The case sensitivity, wildcard and minimal matching options are not changed..PPSee also pattern()..SH "void QRegExp::setWildcard ( bool wildcard )"Sets the wildcard mode for the regular expression. The default is FALSE..PPSetting \fIwildcard\fR to TRUE enables simple shell-like wildcard matching. (See wildcard matching (globbing).).PPFor example, \fBr*.txt\fR matches the string \fCreadme.txt\fR in wildcard mode, but does not match \fCreadme\fR..PPSee also wildcard()..SH "bool QRegExp::wildcard () const"Returns TRUE if wildcard mode is enabled, otherwise FALSE. The default is FALSE..PPSee also setWildcard()..SH "SEE ALSO".BR http://doc.trolltech.com/qregexp.html.BR http://www.trolltech.com/faq/tech.html.SH COPYRIGHTCopyright 1992-2001 Trolltech AS, http://www.trolltech.com.  See thelicense file included in the distribution for a complete licensestatement..SH AUTHORGenerated automatically from the source code..SH BUGSIf you find a bug in Qt, please report it as described in.BR http://doc.trolltech.com/bughowto.html .Good bug reports help us to help you. Thank you..PThe definitive Qt documentation is provided in HTML format; it islocated at $QTDIR/doc/html and can be read using Qt Assistant or witha web browser. This man page is provided as a convenience for thoseusers who prefer man pages, although this format is not officiallysupported by Trolltech. .PIf you find errors in this manual page, please report them to.BR qt-bugs@trolltech.com .Please include the name of the manual page (qregexp.3qt) and the Qtversion (3.0.0).

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -