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

int QRegExp::pos ( int  nth = 0  ) 

Returns the position of the nth captured text in the searched string. If nth is 0 (the default), pos() returns the position of the whole match.

Example:

    QRegExp rx( "/([a-z]+)/([a-z]+)" );
    rx.search( "Output /dev/null" );    // returns 7 (position of /dev/null)
    rx.pos( 0 );                        // returns 7 (position of /dev/null)
    rx.pos( 1 );                        // returns 8 (position of dev)
    rx.pos( 2 );                        // returns 12 (position of null)

For 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.

See also:
capturedTexts() exactMatch() search() searchRev()

Definition at line 3883 of file qregexp.cpp.

{
    if ( nth < 0 || nth >= (int) priv->captured.size() / 2 )
      return -1;
    else
      return priv->captured[2 * nth];
}


Generated by  Doxygen 1.6.0   Back to index