• 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: Michael Terry <email@hidden>
  • Date: Fri, 6 Feb 2004 14:04:15 -0800

On Feb 6, 2004, at 12:59 PM, Hanaan Rosenthal wrote:

I'm having to deal with searching through text containing thousands of
lines for matches.
The text is tab delimited, where one field contains the wrong word and
the second contains the right word. I'm using it as the dictionary for
search and replace.
The text looks like that:
"GM General Motors
Macdonalds McDonalds
MicroSoft Microsoft
etc..."

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.


Using Satimage, this will return a list of all such matching lines:

find text "^macdonalds.*" in (choose file) with regexp, string result and all occurrences

Each line, by default, is considered a separate record, and the pattern will try to match within that. The caret (^) matches the beginning of the record, the dot (.)[1] matches any character, and the star (*) tell the dot to keep on matching until the end of the record.

'string result' is Satimage's way of saying that you want the actual text rather than match positions within the text, and 'all occurrences' ensures that we get each matching record (line) rather than just the first match.

Mike

[1] Heh.
_______________________________________________
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>)

  • Prev by Date: Re: Regex in OS X
  • Next by Date: Re: Regex in OS X
  • Previous by thread: Re: Regex in OS X
  • Next by thread: Re: Regex in OS X
  • Index(es):
    • Date
    • Thread