• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: OS X and RegEx Commands
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: OS X and RegEx Commands


  • Subject: Re: OS X and RegEx Commands
  • From: Christopher Stone <email@hidden>
  • Date: Mon, 1 Dec 2003 23:47:03 -0600

At 16:02 +0100 12/01/2003, Christian Vinaa wrought:

what I basically need to do

(and mind you that I made the scripts some years ago and since then been too busy to dabble with applescript - sadly though - so i'm a bit rusty)

is this; (getting specific info from an email:)

set myEmailtext1 to (REMatchLines bodyText pattern textTofind1)
______________________________________________________________________

Hello Christian,

set theText to "one
two
three
one
two
three"

This will find the first result:

try
set findIt to find text "one" in theText with regexp and string result without case sensitive
on error
set findIt to false
end try


This will find all occurrences:

try
set findIt to find text "one" in theText with regexp, all occurrences and string result without case sensitive
on error
set findIt to false
end try

This will match lines:

set theText to "one of the best
two of the worst
three of the craziest
one ring to rule them all
two turtle doves
three stooges"

try
set findIt to find text "^.*one.*" in theText with regexp, all occurrences and string result without case sensitive
on error
set findIt to false
end try

You may want to play with this handler:

--
=============================================================================
-->> Find using Satimage osax - returns boolean AND result
--
=============================================================================
on fnd(findStr, usingStr, theText, regexFlags, stringResultFlag, allOcFlag)
try
find text findStr in theText using usingStr regexpflag regexFlags string result stringResultFlag all occurrences allOcFlag with regexp
return true
on error
return false
end try
end fnd

if fnd("()", "\\1", theText, {"EXTENDED", "NEWLINE", "ICASE"}, true, false) of me then
set theValue to result
end if

The newline parameter forces line-grep or in RegEx commands parlance REMatchLines. Removing it will allow for the longest match.

try
set findIt to find text "^.*one.*" in theText regexpflag {"EXTENDED", "NEWLINE", "ICASE"} with regexp and string result
on error
set findIt to false
end try

** Note that you need to use a try...end try block, because the Satimage osax find event will throw an error if nothing is found.

Holler at me if you need any help. I use this thing every day.


Chris
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: OS X and RegEx Commands (From: Christian Vinaa <email@hidden>)

  • Prev by Date: Word processor with best scriptable search/replace
  • Next by Date: Re: Telling remote computer to "do shell script"
  • Previous by thread: Re: OS X and RegEx Commands
  • Next by thread: Re: OS X and RegEx Commands
  • Index(es):
    • Date
    • Thread