Previous Index Next

BridgePlus.framework, SMSForder Class Methods

Category

Regular Expression methods

Method

findMatchRecords:inString:options:captureGroups:

Summary

Returns an array of match records for each match, sorted in your specified capture group order. If no matches are found, the overall result will be missing value.

Signature

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

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 containing subarrays of the match record dictionaries for each specified capture group. If no matches are found, the overall result will be missing value. 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 price is $39.99"

set theResult to current application's SMSForder's findMatchRecords:"(\\d+)\\.(\\d+)" inString:aString options:"" captureGroups:{0, 1, 2}

ASify from theResult

--> {{{foundRange:{location:14, length:5}, captureGroup:0, foundString:"39.99"}, {foundRange:{location:14, length:2}, captureGroup:1, foundString:"39"}, {foundRange:{location:17, length:2}, captureGroup:2, foundString:"99"}}}

theResult as list -- only in 10.10 and later

--> {{{foundRange:{location:14, length:5}, captureGroup:0, foundString:"39.99"}, {foundRange:{location:14, length:2}, captureGroup:1, foundString:"39"}, {foundRange:{location:17, length:2}, captureGroup:2, foundString:"99"}}}


set aString to "The price is $39.99, normally $49.99"

set theResult to current application's SMSForder's findMatchRecords:"(\\d+)\\.(\\d+)" inString:aString options:"" captureGroups:{1, 2}

ASify from theResult

--> {{{foundRange:{location:14, length:2}, captureGroup:1, foundString:"39"}, {foundRange:{location:17, length:2}, captureGroup:2, foundString:"99"}}, {{foundRange:{location:31, length:2}, captureGroup:1, foundString:"49"}, {foundRange:{location:34, length:2}, captureGroup:2, foundString:"99"}}}

theResult as list

--> {{{foundRange:{location:14, length:2}, captureGroup:1, foundString:"39"}, {foundRange:{location:17, length:2}, captureGroup:2, foundString:"99"}}, {{foundRange:{location:31, length:2}, captureGroup:1, foundString:"49"}, {foundRange:{location:34, length:2}, captureGroup:2, foundString:"99"}}}


Click here to open script in a script editor