Previous | Index | Next |
Regular Expression methods
findFirstMatch:inString:options:
Returns the first matching string found. If none found, returns missing value.
+ (NSString *)findFirstMatch:(NSString *)regexPattern inString:(NSString *)searchString options:(NSString *)optionsString
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
An NSString or missing value
Version 1.0.0
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 findFirstMatch:"c[^a]t" inString:aString options:""
ASify from theResult
--> "cot"
theResult as text -- only in 10.10 and later
--> "cot"
set theResult to current application's SMSForder's findFirstMatch:"th." inString:aString options:""
ASify from theResult
--> "the"
theResult as text
--> "the"
set theResult to current application's SMSForder's findFirstMatch:"th." inString:aString options:"i"
ASify from theResult
--> "The"
theResult as text
--> "The"