class KRegExp

Regular expression (regexp) matching with back-references. More...

Definition#include <kregexp.h>
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

Public Methods

Protected Members


Detailed Description

Regular expression (regexp) matching with back-references.

This was implemented because QRegExp does not support back-references.

Back-references are parts of a regexp grouped with parentheses. If a string matches the regexp, you can access the text that matched each group with the group method. This is similar to regular expressions in Perl.

Example:


  KRegExp ex( "([A-Za-z]+) (.+)" );
  ex.match( "42 Torben Weis" );
  qDebug( ex.group(0) );
  qDebug( ex.group(1) );
  qDebug( ex.group(2) );

Output:


  Torben Weis
  Torben
  Weis

Please notice that KRegExp does @bf not support unicode.

KRegExp ()

Create a KRegExp object without a default pattern.

KRegExp ( const char *_pattern, const char *_mode = "" )

Create a KRegExp object.

Parameters:
_patternThe regular expression to use for matches.
_modeIf this is "i", case-insensitive matches will be performed.

bool compile ( const char *_pattern, const char *_mode = "" )

Prepare a regular expression for subsequent matches.

Parameters:
_patternThe regular expression to use for matches.
_modeIf this is "i", case-insensitive matches will be performed.

bool match ( const char *_string )

Match a string to the last supplied regexp.

Returns: true on match, false otherwise.

const char * group ( int _grp )

Parameters:
_grpMay be in the range [0..9]. If _grp is 0 then the complete matched string is returned.

Returns: a grouped substring. A substring may be empty. In this case 0 is returned. Otherwise you may @bf not delete or modify the returned value. In addition the returned value becomes invalid after the KRegExp instance is deleted or after @ref @match() was called again.

int groupStart ( int _grp )

Parameters:
_grpMay be in the range [0..9]. If _grp is 0 then the start offset of the complete matched string is returned.

Returns: The start offset of the grouped substring.

int groupEnd ( int _grp )

Parameters:
_grpMay be in the range [0..9]. If _grp is 0 then the end offset of the complete matched string is returned.

Returns: The end offset of the grouped substring. The "end offset" is the first character after the string.