Re: Capturing parts of text string [Re: Applescript-users Digest, Vol 2, Issue 443]
Re: Capturing parts of text string [Re: Applescript-users Digest, Vol 2, Issue 443]
- Subject: Re: Capturing parts of text string [Re: Applescript-users Digest, Vol 2, Issue 443]
- From: has <email@hidden>
- Date: Tue, 5 Jul 2005 19:14:12 +0100
doug rogers wrote:
>>Dealing with uncertain whitespace padding is absolutely trivial when using regular expressions:
>>search txt for "^\\s*(.*?)\\s*,\\s*(.*?)\\s+([-0-9]+)\\s*$" with regex and individual line matching
>
>Ha Ha Ha Ha ha...... :-)
Not entirely sure what that means, but anyway, here's the original RE:
^(.*?),(.*?) ([-0-9]+)$
and here it is tweaked to allow for messy whitespace padding:
^\\s*(.*?)\\s*,\\s*(.*?)\\s+([-0-9]+)\\s*$
All I've done is add '\s*' ("match zero or more whitespace characters") wherever it should ignore whitespace and changed the one significant space separator to a more forgiving '\s+' ("match one or more whitespace characters"). Like I say, a trivial modification to make and quite robust.
>>They take a little bit of learning but it's totally worth it, and there's loads of printed and online resources to help; not just tutorials but scads of ready-to-use patterns
>
>Sources for these?
Google is your friend, as always: <http://www.google.com/search?q=regular+expression>. No shortage of tutorials there. Or search Amazon for "regular expressions" if you prefer dead-treee format.
There's some background reading and good links on wikipedia: <http://en.wikipedia.org/wiki/Regular_expression>
There's a collection or ready-made REs here: <http://www.regexlib.com>
Bear in mind that RE features and syntax can vary a bit from implementation to implementation, so not everything you read about System X will be exactly the same for System Y (e.g. POSIX-style REs would use '[[:space:]]' instead of '\s'), but the basic principles and syntax are generally the same - and more than enough to blow away any ad-hoc vanilla AS alternative.
HTH
has
p.s. I'm currently working on better documentation for TextCommands, though I probably won't write a full RE tutorial unless folk want to sponsor it. (If anyone has a favourite RE tutorial they think would be ideal for ASers, do let me know and I'll include a link to it.)
--
http://freespace.virgin.net/hamish.sanderson/
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden