Previous Index Next

BridgePlus.framework, SMSForder Class Methods

Category

Regular Expression methods

Method

findMatchRecords:inString:options:

Summary

Returns an array of the match records found. If none found, returns an empty array.

Signature

+ (NSArray *)findMatchRecords:(NSString *)regexPattern inString:(NSString *)searchString options:(NSString *)optionsString

Parameters

regexPattern = ICY regular expression pattern; see http://userguide.icu-project.org/strings/regexp.

searchString = string to search

optionsString = a string containing any or all of the following letters:

i Makes the search case insensitive

x Allows white space and #comments in the pattern

s Makes the "." character match a line terminator

m Makes "^" and "$" match the start/end of every line, not just the whole string

w Makes \b match word boundaries as described in Unicode UAX 29, rather than traditional regular expression behavior

Result

An array of match record dictionaries. The format of a matchRecord dictionary is: {captureGroup:#, foundString:"found string", foundRange:{location:n, length:nn}}. For non-existent capture groups or capture groups that do not participate in a particular match, the foundString will be missing value, with a foundRange of {location:NSNotFound, length:0}.

Availability

Version 1.0.0

Notes

 

Sample

use scripting additions

use framework "Foundation"

use script "BridgePlus"

load framework


set aString to "The cat sat in the cot"

set theResult to current application's SMSForder's findMatchRecords:"c.t" inString:aString options:""

ASify from theResult

--> {{foundRange:{location:4, length:3}, captureGroup:0, foundString:"cat"}, {foundRange:{location:19, length:3}, captureGroup:0, foundString:"cot"}}

theResult as list -- only in 10.10 and later

--> {{foundRange:{location:4, length:3}, captureGroup:0, foundString:"cat"}, {foundRange:{location:19, length:3}, captureGroup:0, foundString:"cot"}}


set theResult to current application's SMSForder's findMatchRecords:"th." inString:aString options:""

ASify from theResult

--> {{foundRange:{location:15, length:3}, captureGroup:0, foundString:"the"}}

theResult as list

--> {{foundRange:{location:15, length:3}, captureGroup:0, foundString:"the"}}


set theResult to current application's SMSForder's findMatchRecords:"th." inString:aString options:"i"

ASify from theResult

--> {{foundRange:{location:0, length:3}, captureGroup:0, foundString:"The"}, {foundRange:{location:15, length:3}, captureGroup:0, foundString:"the"}}

theResult as list

--> {{foundRange:{location:0, length:3}, captureGroup:0, foundString:"The"}, {foundRange:{location:15, length:3}, captureGroup:0, foundString:"the"}}


Click here to open script in a script editor