Previous Index Next

BridgePlus.framework, SMSForder Class Methods

Category

Regular Expression methods

Method

findFirstMatchRecord:inString:options:

Summary

Returns the first match record found. If none found, returns missing value.

Signature

+ (NSDictionary *)findFirstMatchRecord:(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

A match record dictionary or 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 cat sat in the cot"

set theResult to current application's SMSForder's findFirstMatchRecord:"c[^a]t" inString:aString options:""

ASify from theResult

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

theResult as record -- only in 10.10 and later

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


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

ASify from theResult

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

theResult as record

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


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

ASify from theResult

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

theResult as record

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


Click here to open script in a script editor