NSData RegexKit Additions Reference

Extends by categoryNSData
RegexKit0.6.0 Release Notes
PCRE7.6
AvailabilityAvailable in Mac OS X v10.4 or later.
Declared in
  • RegexKit/NSData.h
Overview

RKCompileOption Requirements

Unlike the other Foundation additions, the NSData additions do not require and do not set the RKCompileUTF8 and RKCompileNoUTF8Check compile option flags due to the fact that NSData objects represent raw byte buffers.

Important:
Some Unicode regular expression escapes sequences are not available unless RKCompileUTF8 is set. If you require this functionality, or the data contained by the NSData object is UTF8 Unicode data, you will need to instantiate a RKRegex with the RKCompileUTF8 option set.

Specifying a Regular Expression

When specifying a regular expression, the regular expression can be either a RKRegex object or a NSString containing the text of a regular expression. When specified as a NSString, as determined by sending isKindOfClass:, the receiver will convert the string to a RKRegex object via regexWithRegexString:options:.

Important:
The method will raise NSInvalidArgumentException if the regular expression is nil. If passed as a NSString, the method will raise RKRegexSyntaxErrorException if the regular expression is not valid.

Determining if an Object Matches a Regular Expression

Objects are sent isMatchedByRegex: to determine whether or not they are matched by the specified regular expression.

Tasks

Accessing Data
Determining the Range of a Match
Testing Data

Instance Methods

Returns a Boolean value that indicates whether the receiver is matched by aRegex.
- (BOOL)isMatchedByRegex:(id)aRegex;
Returns a Boolean value that indicates whether the receiver is matched by aRegex within range.
- (BOOL)isMatchedByRegex:(id)aRegex inRange:(const NSRange)range;
Returns the range of the first occurrence within the receiver of aRegex.
- (NSRange)rangeOfRegex:(id)aRegex;
Return Value
A NSRange structure giving the location and length of the first match of aRegex in the receiver. Returns {NSNotFound, 0} if the receiver is not matched by aRegex.
Returns the range of aRegex capture number capture for the first match within range of the receiver.
- (NSRange)rangeOfRegex:(id)aRegex inRange:(const NSRange)range capture:(const RKUInteger)capture;
Parameters
  • aRegex
    A regular expression string or RKRegex object.
  • range
    The range of the receiver to search.
  • capture
    The matching range of aRegex capture number to return. Use 0 for the entire range that aRegex matched.
Return Value
A NSRange structure giving the location and length of aRegex capture number capture for the first match within range of the receiver. Returns {NSNotFound, 0} if the receiver is not matched by aRegex.
See Also
Returns a pointer to an array of NSRange structures of the capture subpatterns of aRegex for the first match in the receiver.
- (NSRange *)rangesOfRegex:(id)aRegex;
Discussion
See rangesForCharacters:length:inRange:options: for details regarding the returned NSRange array memory allocation.
Return Value
Returns a pointer to an array of NSRange structures of the capture subpatterns of aRegex for the first match in the receiver, or NULL if aRegex does not match.
Returns a pointer to an array of NSRange structures of the capture subpatterns of aRegex for the first match in the receiver within range.
- (NSRange *)rangesOfRegex:(id)aRegex inRange:(const NSRange)range;
Discussion
See rangesForCharacters:length:inRange:options: for details regarding the returned NSRange array memory allocation.
Return Value
Returns a pointer to an array of NSRange structures of the capture subpatterns of aRegex for the first match in the receiver within range, or NULL if aRegex does not match.
Returns a NSData that contains the bytes of the first match by aRegex.
- (NSData *)subdataByMatching:(id)aRegex;
Returns a NSData that contains the bytes of the first match by aRegex within range.
- (NSData *)subdataByMatching:(id)aRegex inRange:(const NSRange)range;
 
RegexKit project hosted by: