Main Page   Modules   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   Related Pages  

KRegExp Class Reference

#include <kregexp.h>

List of all members.

Public Methods

 KRegExp ()
 KRegExp (const char *_pattern, const char *_mode="")
bool compile (const char *_pattern, const char *_mode="")
bool match (const char *_string)
const char * group (int _grp)
int groupStart (int _grp)
int groupEnd (int _grp)


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.

Author:
Torben Weis <weis@kde.org>
Version:
Id:
kregexp.h,v 1.11 2002/09/14 16:49:02 tjansen Exp

Definition at line 54 of file kregexp.h.


Constructor & Destructor Documentation

KRegExp::KRegExp  
 

Creates a KRegExp object without a default pattern.

KRegExp::KRegExp const char *    _pattern,
const char *    _mode = ""
 

Creates a KRegExp object.

Parameters:
_pattern  The regular expression to use for matches.
_mode  If this is "i", case-insensitive matches will be performed.


Member Function Documentation

bool KRegExp::compile const char *    _pattern,
const char *    _mode = ""
 

Prepare a regular expression for subsequent matches.

Parameters:
_pattern  The regular expression to use for matches.
_mode  If this is "i", case-insensitive matches will be performed.
Returns:
bool if successful.

const char* KRegExp::group int    _grp
 

Returns a group from the match.

Parameters:
_grp  May 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 match() was called again.

int KRegExp::groupEnd int    _grp
 

The offset of the given group's end in the string.

Parameters:
_grp  May 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.

int KRegExp::groupStart int    _grp
 

The offset of the given group in the string.

Parameters:
_grp  May 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.

bool KRegExp::match const char *    _string
 

Match a string to the last supplied regexp.

Parameters:
_string  the string to match
Returns:
true on match, false otherwise.


The documentation for this class was generated from the following file:
Generated on Wed Aug 13 23:30:22 2003 for kdelibs by doxygen1.2.18