Inherits from NSObject
Conforms to NSCopying
Declared in PXRegexPattern.h
PXRegexPattern.m

Overview

A PXRegexPattern creates a compiled regex string from the given info. This is used to find matches later. A PXRegexPattern object is immutable.

Example:

PXRegexPattern *pattern = [[PXRegexPattern alloc] initWithRegex:@"^(\\w+)\\s(.*)$"];
PXRegexMatcher *matcher = [[PXRegexMatcher alloc] initWithPattern:pattern string:@"person name:Steve age:56"];
[pattern release];

// If there are lots of potential matches, a while loop should be used.
if ([matcher next])
{
    NSLog (@"%@", [matcher groupAtIndex:0]); // @"person name:Steve age:56"
    NSLog (@"%@", [matcher groupAtIndex:1]); // @"person"
    NSLog (@"%@", [matcher groupAtIndex:2]); // @"name:Steve age:56"
}

[matcher release];

Tasks

Properties

capturingGroupCount

Returns the number of capturing groups in this matcher’s pattern.

@property (nonatomic, readonly) unsigned capturingGroupCount

Discussion

Group zero denotes the entire pattern by convention. It is not included in this count.

Declared In

PXRegexPattern.h

flags

A list of PXRegexPatternFlag flags that will define how the regex is compiled.

@property (nonatomic, readonly) unsigned flags

Declared In

PXRegexPattern.h

regex

The compiled regex pattern.

@property (nonatomic, readonly) NSString *regex

Declared In

PXRegexPattern.h

Class Methods

patternWithRegex:flags:

Creates a regex pattern.

+ (PXRegexPattern *)patternWithRegex:(NSString *)regex flags:(unsigned)flags

Parameters

flags

The flags explaining how to compile the regex.

pattern

The regex to compile. If regex is not nil then it immediately compiles the regex.

Return Value

The resulting, autoreleased, @PXRegexPattern object.

Declared In

PXRegexPattern.m

quoteString:

Not yet implemented

+ (NSString *)quoteString:(NSString *)input

Declared In

PXRegexPattern.m

splitString:

Invokes splitString:limit: using 0 as the limit.

+ (NSArray *)splitString:(NSString *)input

Declared In

PXRegexPattern.m

splitString:limit:

Not yet implemented

+ (NSArray *)splitString:(NSString *)input limit:(int)limit

Declared In

PXRegexPattern.m

Instance Methods

matcherWithInput:

Creates a new PXRegexMatcher object containing all information needed to match your strings with the compiled regex.

- (PXRegexMatcher *)matcherWithInput:(NSString *)input

Parameters

string

The string to find matches for.

Return Value

The new PXRegexMatcher object.

Declared In

PXRegexPattern.m