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

Re: Regex on OS X


  • Subject: Re: Regex on OS X
  • From: "Dennis W. Manasco" <email@hidden>
  • Date: Fri, 4 Oct 2002 03:50:00 -0500

At 8:34 am -0700 10/3/02, bill fancher wrote:

On Wednesday, October 2, 2002, at 03:25 AM, John Delacour wrote:

I notice you have not actually supplied the UNIX shell script that _does_ print all the lines whose name is 'Jan' and not 'Jan*' without the preceding number and space. I look forward to seeing this.

AppleScript is quite capable of doing this unaided, but, for your amusement and derision:

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
9 Moose
"
set cmd to "echo '" & s & "'|awk '/Jan[ \\t]+/ {sub(/[0-9]*[ \\t]+/,\"\");print}'"
set text item delimiters to (ASCII character 10) -- to convert CR to LF
do shell script paragraphs of cmd as text -- convert CR to LF and run script

[Just to poke a small stick in the hive.. ;->]

Change the list to:

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
9 Moose
10 Marcello Jan
11 jan janson
"
Oops, we're short a couple of Jans!

At 8:06 pm +0100 10/3/02, John Delacour wrote:

do shell script "perl -e '
$r = chr(13) ; @lines = split /$r/, qq~" & s & "~;
for(@lines) {/(\\d+\\s+)(Jan[^\\w].+)/ and print qq~$2$r~}'"

Same (modified) challenge.

By the way: Notice a difference between the two versions if we add the line

12 Erica Jan Thompson

I'm actually quite interested to know what it would take to modify either example to the new condition(s). Both examples are very interesting, though I haven't spent the time to really figure out either one.


Best wishes,

-=-Dennis
_______________________________________________
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: Regex on OS X (From: bill fancher <email@hidden>)

  • Prev by Date: Re: Script previously working has suddenly stopped!
  • Next by Date: Re: 'sort' command-alternative?
  • Previous by thread: Re: Regex on OS X
  • Next by thread: Re: Regex on OS X
  • Index(es):
    • Date
    • Thread