Logo Search packages:      
Sourcecode: cb2bib version File versions

int EQRegExp::indexIn ( const QString &  str,
int  offset = 0,
CaretMode  caretMode = CaretAtZero 
) 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::indexOf(), QString::contains(), or even QStringList::filter(). To replace matches use QString::replace().

Example:

        QString str = "offsets: 1.23 .50 71.00 6.00";
        EQRegExp rx("\\d*\\.\\d+");    // primitive floating point matching
        int count = 0;
        int pos = 0;
        while ((pos = rx.indexIn(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().

If the EQRegExp is a wildcard expression (see setPatternSyntax()) and want to test a string against the whole wildcard expression, use exactMatch() instead of this function.

See also:
lastIndexIn(), exactMatch()

Definition at line 3774 of file eqregexp.cpp.

{
    prepareEngineForMatch(priv, str);
    if (offset < 0)
        offset += str.length();
    priv->matchState.match(str, offset, priv->min, false, caretIndex(offset, caretMode));
    return priv->matchState.captured.at(0);
}


Generated by  Doxygen 1.6.0   Back to index