• 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 ignores space in pattern
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: RegEx ignores space in pattern


  • Subject: Re: RegEx ignores space in pattern
  • From: Hans Haesler <email@hidden>
  • Date: Fri, 19 Mar 2004 21:52:42 +0100

Thanks for all replies.

This untested (amazing!!!) one, I've got off-line:
---
"[0-9][0-9]+( [0-9][0-9]+)+-[0-9][0-9]"
---
It works perfectly. It can be simplified to:
---
"[0-9]+( [0-9]+)+-[0-9][0-9]"
---

The background: for searching the text, a variable is set to stories
from a QuarkXPress document. The stories contain many numbers
whose formatting is identical: "12 34 56-78". The "123 456-78" or
the "1234 56-78" are not present in the same series.

The mentioned "12-34-567" is not one of the article numbers
but, e.g. the values of a zoom factor, buried in the description
of an article.

An earlier version of the script asked the user to enter a
sample of the formatting. The the reply was transformed in
a character-by-character search pattern. And the "12-34-567"
zoom value hasn't been a problem.

It popped up, when I decided to make a user-friendlier version:
No dialog, but the script tries to find the first occurrance of
one of the three given forms. As soon as it is found, the result
is transformed to a search pattern which excludes other numbers.
---
set foundPattern to REMatch aString pattern "[0-9]+( [0-9]+)+-[0-9][0-9]"
-->"218 347-29"

compPat(foundPattern)

on compPat(foundPattern)
set patVar to ""
repeat with i from 1 to count foundPattern
set curChar to character i of foundPattern
if curChar is in "0123456789" then
set patVar to patVar & "[0-9]"
else
set patVar to patVar & curChar
end if
end repeat
return patVar
end compPat
-->"[0-9][0-9][0-9] [0-9][0-9][0-9]-[0-9][0-9]"
---
This pattern is used for getting the positions of the numbers
in many QuarkXPress text boxes...
---
set aOff to matchPos of (find text patVar in actPara with regexp)
---
... in order to replace the last two digits with a given number.

And, yes, John is right. Beware, because the article numbers were
typed by humans...

---
Hans Haesler <email@hidden>
_______________________________________________
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 ignores space in pattern (From: Hans Haesler <email@hidden>)
 >Re: RegEx ignores space in pattern (From: "John W. Baxter" <email@hidden>)

  • Prev by Date: Re: Hat bug.
  • Next by Date: Re: [OT] Re: Hat bug.
  • Previous by thread: Re: RegEx ignores space in pattern
  • Next by thread: Re: RegEx ignores space in pattern
  • Index(es):
    • Date
    • Thread