set aString to current application's class "NSString"'s stringWithString :( "I am a string" ) set matchRange to aString's rangeOfString :( "\\S++$" ) ¬ options :( current application's NSRegularExpressionSearch ) range :( Use AppleScript version "2.4" - OS X 10.10 (Yosemite) or later use framework "Foundation" - Get the run of non-white-space at the end, if any. The scripts below assume it's known that the strings will consist of just one line. The alternatives at the moment are to use one of the text-editing languages available through the do shell script command (AppleScript's own StandardAdditions OSAX does still work) or to use AppleScriptObjectiveC. (One of Apple's increasingly tight security measures.) They are allowed under very strict conditions as part of an application's own resources and Late Night Software, the developer of Script Debugger, has released a SatimageOSAX application as a stop-gap measure to allow existing Satimage-dependent scripts to be used with minimal editing until they're rewritten to use other commands. Try find text ".*string$" in "I am a string" with regexp on error message return message end try try change "original" into "modified" in "I am the original string" with regexp on error message return message end tryĪs from macOS 10.14 Mojave, third-party scripting additions (OSAXen) such as the Satimage OSAX are essentially unusable. First - 1 ) & "pattern" & Str ( Last + 1. Compile ( "(PATTERN)" ), Str, First, Last, Found ) Str := Str ( Str ' First. Str ' Last ), First, Last, Found ) exit when not Found Put_Line ( "" ) Current_First := Last + 1 end loop - second, replace "PATTERN" in Str by "pattern" Search_For_Pattern ( Pat. Compile ( Word_Pattern ), Str ( Current_First. Last end if end Search_For_Pattern Word_Pattern : constant String := "(+)" Str : String := "I love PATTERN matching!" Current_First : Positive := Str ' First First, Last : Positive Found : Boolean begin - first, find all the words in Str loop Search_For_Pattern ( Pat. No_Match ) if Found then First := Result ( 1 ). Match ( Compiled_Expression, Search_In, Result ) Found := not Pat. Pattern_Matcher Search_In : String First, Last : out Positive Found : out Boolean ) is Result : Pat. With Ada.Text_IO with Gnat.Regpat use Ada.Text_IO procedure Regex is package Pat renames Gnat.Regpat procedure Search_For_Pattern ( Compiled_Expression : Pat.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |