• 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: Help with find text command
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help with find text command


  • Subject: Re: Help with find text command
  • From: Doug McNutt <email@hidden>
  • Date: Wed, 1 Aug 2007 12:12:38 -0600

At 12:32 -0500 8/1/07, Wallace, William wrote:
>I'm using the find text command from satimage.osax to search a block of text
>to find a string that fits a pattern defined as a regular expression. I have
>the basic regexp working but I'm looking to refine it a little and, being a
>regexp newb, I'm wondering if what I want to do is even possible. The
>string(s) I'm looking for are in the following format:
>
>[1-5 digits][hyphen][1-7 digits][hyphen][1-7 digits][hyphen][1 digit (which
>may actually be an "X")]
>
>This is the command that I have so far to match this:
>
>--
>find text
>"[[:digit:]]{1,5}-[[:digit:]]{1,7}-[[:digit:]]{1,7}-[[:digit:]X]{1}" in
>theText with regexp and all occurrences
>--
>
>Seems to work fine up to a point. However, it occurred to me that the regexp
>could match this string: "0-0-0-0". Which is not at all what I want. I'm
>looking for 10 digit ISBNs in the block of text (which should always be 13
>characters--10 digits divided into 4 substrings by 3 hyphens). Is there a
>way that I can maintain the flexibility in the number of digits within each
>substring, but insist that the total number of characters in the matched
>string remain constant at 13?

>PS - 'Do shell script' alternatives welcome.  ;-}

;-} ing. . .
Testing the length of each match as it is found doesn't seem so bad.

#!/usr/bin/perl
while ($theText =~ m/(\d{1,5})-(\d{1,7})-(\d{1,7})-([X\d])/g)
	{
	my $tmp = $1$2$3$4;
	next if ($length $tmp) != 13;
	push @alist,  "$1-$2-$3-$4";
	}


--

--> From the U S of A, the only socialist country that refuses to admit it. <--
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Help with find text command (From: "Wallace, William" <email@hidden>)

  • Prev by Date: Re: AppleScript and shell scripting
  • Next by Date: Re: Help with find text command
  • Previous by thread: Re: Help with find text command
  • Next by thread: Re: Help with find text command
  • Index(es):
    • Date
    • Thread