Logo Search packages:      
Sourcecode: qt-x11-free version File versions

int QRegExp::search ( const QString str,
int  offset,
CaretMode  caretMode 
) const

Attempts to find a match in str from position offset (0 by default). If offset is -1, the search starts at the last character; if -2, at the next to last character; etc.

Returns the position of the first match, or -1 if there was no match.

The caretMode parameter can be used to instruct whether ^ should match at index 0 or at offset.

You might prefer to use QString::find(), QString::contains() or even QStringList::grep(). To replace matches use QString::replace().

Example:

      QString str = "offsets: 1.23 .50 71.00 6.00";
      QRegExp rx( "\\d*\\.\\d+" );    // primitive floating point matching
      int count = 0;
      int pos = 0;
      while ( (pos = rx.search(str, pos)) != -1 ) {
          count++;
          pos += rx.matchedLength();
      }
      // pos will be 9, 14, 18 and finally 24; count will end up as 4

Although const, this function sets matchedLength(), capturedTexts() and pos().

See also:
searchRev() exactMatch()

Definition at line 3661 of file qregexp.cpp.

References QString::length().

{
    prepareEngineForMatch( str );
    if ( offset < 0 )
      offset += str.length();
    eng->match( str, offset, priv->min, FALSE, caretIndex(offset, caretMode),
            priv->captured );
    return priv->captured[0];
}


Generated by  Doxygen 1.6.0   Back to index