• 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: Regex in OS X
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Regex in OS X


  • Subject: Re: Regex in OS X
  • From: Hanaan Rosenthal <email@hidden>
  • Date: Fri, 6 Feb 2004 23:03:01 -0500

Christopher, Michael, BJ and Walter, Thank you all for responding.
I got my answer and can move on.
I was worried that the process will get bogged down but using Satimage
Reg. expressions is lightning-fast!
Thanks,
Hanaan

On Feb 6, 2004, at 4:46 PM, Christopher Stone wrote:

> At 15:59 -0500 02/06/2004, Hanaan Rosenthal wrought:
>
>> I know Satimage has some regular expressions to handle such a thing.
>> Would anyone (Emmanuel) have some code that will return the line that
>> contains a match at the start of the line. Example:
>> Search string: "Macdonalds"
>> Result is the line:
>> "Macdonalds McDonalds"
>> Since it starts with the search string.
> ______________________________________________________________________
>
> Hey Hanaan,
>
> This is one is particularly easy:
>
> ----------------------------------------------------------------------
> set theText to "
> GM General Motors
> Macdonalds McDonalds
> MicroSoft Microsoft
> "
>
> try
> set findIt to find text "^Macdonalds.+" in theText with regexp and
> string result without case sensitive
> on error
> set findIt to false
> end try
> ----------------------------------------------------------------------
>
> The pattern is: "^Macdonalds.+"
>
> ^ == beginning of line
> . == any character
> + == one or more
>
> ----------------------------------------------------------------------
>
> If you're operating directly on a file you can use that in the
> reference:
>
> set theFile to alias "some:file:path"
>
> try
> set findIt to find text "^Macdonalds.+" in theFile with regexp and
> string result without case sensitive
> on error
> set findIt to false
> end try
>
> ----------------------------------------------------------------------
>
> The Satimage osax does line-based regex by default; however, you can
> make it greedy by using flags:
>
> Line regex:
>
> try
> set findIt to find text "" in theText regexpflag {"EXTENDED",
> "NEWLINE", "ICASE"} with regexp and string result
> on error
> set findIt to false
> end try
>
>
> Greedy regex:
>
> try
> set findIt to find text "" in theText regexpflag {"EXTENDED",
> "ICASE"} with regexp and string result
> on error
> set findIt to false
> end try
>
> Using a try block is necessary, because "find text" will throw an
> error if it doesn't find anything.
>
> [CC'd due to the slowness of the list.]
>
>
> 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.
>
>
--
Hanaan Rosenthal * Custom Flow Solutions
MEDIA AUTOMATION CONSULTING
401-487-2957 * email@hidden
* www.customflowsolutions.com *

be successful... ...work less.
_______________________________________________
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: 
 >Regex in OS X (From: Hanaan Rosenthal <email@hidden>)
 >Re: Regex in OS X (From: Christopher Stone <email@hidden>)

  • Prev by Date: Re: Shell-sandwich a file in 2 variable strings
  • Next by Date: Re: Shell-sandwich a file in 2 variable strings
  • Previous by thread: Re: Regex in OS X
  • Next by thread: Re: Regex in OS X
  • Index(es):
    • Date
    • Thread