Re: Regex on OS X
Re: Regex on OS X
- Subject: Re: Regex on OS X
- From: bill fancher <email@hidden>
- Date: Tue, 1 Oct 2002 14:38:10 -0700
On Tuesday, October 1, 2002, at 01:13 PM, John Delacour wrote:
At 2:08 pm -0500 1/10/02, ken wrote:
Does anyone know if there are any osaxen to to
regex searches on OS X? If not, what are my
options? Thanks.
Your best option is to use perl in a 'do shell script' command. This
is one of the great things about OS 10.
Here's a simple example to print all lines that contain 'Jan'
set s to "
1 Jan Smith
2 Jane Smith
3 Jan Jones
4 Jane King
5 Jan Long
6 Jan Mann
7 Janet Hale
8 Janine Winter
"
--
set JAN_HITS to do shell script "perl -e '
@_ = split /\\015/, qq(" & s & ");
for (@_){
/(\\d+\\s+)(Jan[^\\w].+)/ and print qq($2$/)
}'"
Or you could avoid the bone-ugliness of perl (exacerbated by the need
to escape "\") and replace the last five lines with:
set JAN_HITS to do shell script "echo " & s & "|grep Jan"
This echo's the string, pipes the result to grep, and grep searches it
for Jan.
Perhaps the most compelling advantage of either approach here is that
users aren't required to install a third party osax to use the script.
(If grep doesn't do it for you, there's also sed, awk, egrep,...)
--
bill
_______________________________________________
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.