- Inherits from:
- Object
- Declared in:
- DRegEx.h
Object
|
+---DRegEx
Class Description
The RegEx class implements methods for using regular expressions. After
compiling a regular expressing, it can be used to match and search strings.
This class uses the Extended POSIX syntax:
. Match any char (incl. newline) * Match zero or more
+ Match one or more ? Match zero or one
{c} Match exactly c times {min,max} Match min..max times
| Match alternatives [] Match one in the list
[^] Match any except in list [::] Match a class in a list
() Group or subexpression
^ Match begin of line $ Match end of line
Classes: alnum, alpha, blank, cntrl, digit, graph, lower, print, punct,
space, upper, xdigit
Examples:
(aab|zef) matches aab or zef
aa(b|z)ef matches aabef or aazef
[a-c] matches a or b or c
[]de] matches ] or d or e
[^ad] match any except a and b
[[:alpha:]] matches letters (*NOTE*: use ccompile and not icompile)
[.*] matches . and *
- Last modified:
- 31-Oct-2007 (DRegEx.h)
Instance Variables
- private regex_t _pattern
- the compiled pattern
- private struct re_registers _regs
- the match registers
- private int _result
- the result of the last match/search
- private size_t _length
- the length of the last string
- Constructors
- - (DRegEx *) init
- Initialise to an empty expression
- Returns:
- the object
- - (DRegEx *) init :(const char *) pattern
- Initialise with a pattern
- Parameters:
- pattern - the (case sensitive) c-string pattern
- Returns:
- the object
- Copy related methods
- - shallowCopy
- Do a shallow copy of the object (not implemented)
- Returns:
- the object
- Destructor
- - free
- Free the expression
- Returns:
- the object
- Compile methods
- - (BOOL) ccompile :(const char *) pattern
- Compile a case sensitive pattern (POSIX Extended syntax)
- Parameters:
- pattern - the c-string pattern
- Returns:
- success
- - (BOOL) icompile :(const char *) pattern
- Compile a case insensitive pattern (POSIX Extended syntax)
- Parameters:
- pattern - the c-string pattern
- Returns:
- success
- Matching and searching methods
- - (int) match :(const char *) str
- Match the string for the pattern
- Parameters:
- str - the string to be matched
- Returns:
- the number of characters matched (or DRE_NO_MATCH, DRE_ERROR)
- - (int) match :(const char *) str :(int) from
- Match the string with an offset for the pattern
- Parameters:
- str - the string to be matched
from - the start in the string for the matching
- Returns:
- the number of characters matched (or DRE_NO_MATCH, DRE_ERROR)
- - (int) match :(const unsigned char *) data :(int) length :(int) from
- Match the data string with an offset for the pattern
- Parameters:
- data - the data string to be matched
length - the length of the data string
from - the start in the data string for the matching
- Returns:
- the number of characters matched (or DRE_NO_MATCH, DRE_ERROR)
- - (int) search :(const char *) str
- Search in a string for the pattern
- Parameters:
- str - the string to be searched
- Returns:
- the offset in the string where the pattern matched (or DRE_NO_MATCH, DRE_ERROR)
- - (int) search :(const unsigned char *) data :(int) length
- Search in a data string for the pattern
- Parameters:
- data - the data string to be searched
length - the length of the data string
- Returns:
- the offset in the data string where the pattern matched (or DRE_NO_MATCH, DRE_ERROR)
- - (int) search :(const char *) str :(int) from :(int) to
- Search in a range of a string for the pattern
- Parameters:
- str - the string to be searched
from - the start of the range for searching
to - the end of the range for searching
- Returns:
- the offset in the string where the pattern matched (or DRE_NO_MATCH, DRE_ERROR)
- - (int) search :(const unsigned char *) str :(int) length :(int) from :(int) to
- Search in a range of a data string for the pattern
- Parameters:
- data - the data string to be searched
length - the length of the data string
from - the start of the range for searching
to - the end of the range for searching
- Returns:
- the offset in the data string where the pattern matched (or DRE_NO_MATCH, DRE_ERROR)
- Result methods
- - (DArray *) indices
- Return the subexpression indices from the last match/search. The indices
are returned in a DArray with (new) DInt objects. The sequence in the array
is: index 0 = start of whole matched string, index 1 = end of whole matched
string, index 2 = start of first subexpression, index 3 = end of first
subexpression, and so on. Warning: if a group matches more than once as a
result of a repetition operator, only the last match is stored in the indices.
- Returns:
- a (new) array (or nil for no match)
- - (DArray *) matches :(const char *) str
- Return the matches from the last match/search. The matches are
returned in a (new) DArray with (new) DText objects.
- Parameters:
- str - the string that was matched/searched
- Returns:
- a (new) array (or nil for no match)
- - (DArray *) matches :(const unsigned char *) data :(int) length
- Return the matches from the last match/search. The matches
are returned in a (new) DArray with (new) DData objects.
- Parameters:
- data - the data string that was matched/searched
length - the length of the data string
- Returns:
- a (new) array (or nil for no match)
generated 05-Nov-2007 by ObjcDoc 3.0.0