use scripting additions
use framework "Foundation"
set anNSString to current application's NSString's stringWithString:"2/3" -- some date string
-- look for 1-2 digits, slash, followed by 1-2 digits
set theRegex to current application's NSRegularExpression's regularExpressionWithPattern:"(
\\d{1,2})/(?=\\d{1,2})"
options:0
|error|:(
missing value)
set theMatches to theRegex's matchesInString:anNSString options:0 range:{0, anNSString's |length|()}
if (theMatches's |count|()) = 1 then -- must be M/d without year
-- get range of the month
set monthRange to (theMatches's objectAtIndex:0)'s rangeAtIndex:1
-- get month number
set theMonth to (anNSString's substringWithRange:monthRange) as text as integer
-- get year and month of now
set now to current date
set {thisMonth, theYear} to {month of now as integer, year of now}
-- bump year if month would otherwise have passed
if theMonth < thisMonth then set theYear to theYear + 1
-- replace MM/dd with MM/dd/year
set anNSString
to anNSString's
stringByReplacingOccurrencesOfString:"\\d{1,2}/\\d{1,2}" withString:("$0/" & theYear
) options:(current application's NSRegularExpressionSearch
) range:{0, anNSString's
|length|()} end if