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" );
  kdDebug() << ex.group(0) << endl;
  kdDebug() << ex.group(1) << endl;
  kdDebug() << ex.group(2) << endl;

Output:


  Torben Weis
  Torben
  Weis

Please notice that KRegExp does not support unicode.

 KRegExp ()

KRegExp

Create a KRegExp object without a default pattern.

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

KRegExp

Create a KRegExp object.

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

 ~KRegExp ()

~KRegExp

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

compile

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

Match a string to the last supplied regexp.

Returns: true on match, false otherwise.

const char * group ( int _grp )

group

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 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 )

groupStart

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 )

groupEnd

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.

KRegExpPrivate * m_pPrivate

m_pPrivate

[protected]