AppleScript名:ASOCでNSPredicateによる正規表現を併用した抽出 |
— Created 2015-09-28 by Takaaki Naganoya — 2015 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use BridgePlus : script "BridgePlus" —https://www.macosxautomation.com/applescript/apps/BridgePlus.html set sampleList to {{textData:"Piyomaru", uID:1}, {textData:"Xx Piyomaru x", uID:2}, {textData:"xxxxx 11111111 98 x xxxxxxxx.", uID:3}, {textData:"98x Xxxxxx (xx xxxxxxxxxx)", uID:4}, {textData:"<< 98158113 >>", uID:5}, {textData:"#98158084 Xxxxx Xxxxx xxxx", uID:6}, {textData:"#98158084 Xxxxx Xxxxx xxxx", uID:7}, {textData:"Office # 98158107", uID:8}, {textData:"ID#98158087", uID:9}, {textData:"98158089", uID:10}, {textData:"00158098", uID:11}} –全文一致で抽出 set aRes to my filterRecListByLabel1(sampleList, "textData == ’Piyomaru’") –> {{textData:"Piyomaru", uID:1}} –部分一致で抽出 set bRes to my filterRecListByLabel1(sampleList, "textData contains ’Piyomaru’") –> {{textData:"Piyomaru", uID:1}, {textData:"Xx Piyomaru x", uID:2}} –正規表現で抽出(8桁の数字) set cRes to my filterRecListByLabel1(sampleList, "textData MATCHES ’\\\\d{8}’") –> {{textData:"98158089", uID:10}, {textData:"00158089", uID:11}} set dRes to my filterRecListByLabel1(sampleList, "textData MATCHES ’98\\\\d{6}’") –> {{textData:"98158089", uID:10}} set eRes to my filterRecListByLabel1(sampleList, "textData LIKE ’*98??????*’") –> {{textData:"xxxxx 11111111 98 x xxxxxxxx.", uID:3}, {textData:"98x Xxxxxx (xx xxxxxxxxxx)", uID:4}, {textData:"<< 98158113 >>", uID:5}, {textData:"#98158084 Xxxxx Xxxxx xxxx", uID:6}, {textData:"#98158084 Xxxxx Xxxxx xxxx", uID:7}, {textData:"Office # 98158107", uID:8}, {textData:"ID#98158087", uID:9}, {textData:"98158089", uID:10}} set fRes to my filterRecListByLabel1(sampleList, "textData LIKE ’*\"98\"[0-9][0-9][0-9][0-9][0-9][0-9]*’") –Oops!! –> {} set gRes to my filterRecListByLabel1(sampleList, "textData LIKE ’*[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]*’") –Oops!! –> {} set hRes to my filterRecListByLabel1(sampleList, "textData MATCHES ’.*[98]\\\\d{6}.*’") –OK!! –> {{textData:"<< 98158113 >>", uID:5}, {textData:"#98158084 Xxxxx Xxxxx xxxx", uID:6}, {textData:"#98158084 Xxxxx Xxxxx xxxx", uID:7}, {textData:"Office # 98158107", uID:8}, {textData:"ID#98158087", uID:9}, {textData:"98158089", uID:10}} –リストに入れたレコードを、指定の属性ラベルの値で抽出 on filterRecListByLabel1(aRecList as list, aPredicate as string) set aArray to current application’s NSArray’s arrayWithArray:aRecList set aPredicate to current application’s NSPredicate’s predicateWithFormat:aPredicate set filteredArray to aArray’s filteredArrayUsingPredicate:aPredicate set bList to ASify from filteredArray as list return bList end filterRecListByLabel1 |
More from my site
(Visited 19 times, 1 visits today)