On Friday 15 October 2004 10:35, Robet Carson wrote:
> need a regexp to get the contents of this marker or one very simular:
>
> {!STATISTICS:starbucks!}
>
> what I am looking for is to get the "STATISTICS" and "starbucks" into
> an array() if possible.  I believe with the correct regexp this can be
> accomplished using preg_split() or by getting the contents of the
> marker and explode()'ing them.  also i am looking to grab several
> strings for a marker like this, for instance.
>
> {!STASTISTICS:starbucks:blended:chocolate!}
>
> Also if someone could direct me to a site that explains how to use and
> create regexp in a small minded manor since I have been unable to
> grasp the concepts.

A few tips for starting out with regex:

1) use PCRE, they are faster and ultimately more useful than the POSIX variety
2) Build up your regex step-by-step and test it at each step to see what is 
being matched and what isn't (and why it isn't)
3) Use parentheses () to enclose the bits you want to 'capture' (extract).
4) Practice
5) More practice


So for your first example, as a first draft you can just capture everything 
between the begin marker and the end marker:

  $doo = '{!STATISTICS:starbucks!}';
  preg_match('/\{!(.*)!\}/', $doo, $match)

$match[1] now contains: STATISTICS:starbucks

You can explode() it to get the constituent parts.

Or you can refine your regex:

  preg_match('/\{!(.*):(.*)!\}/', $doo, $match)

So basically your first draft would match a large chunk of stuff, your 
successive drafts would fine-tune it until eventually you're matching exactly 
what you need.

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
------------------------------------------
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
------------------------------------------
/*
Today you'll start getting heavy metal radio on your dentures.
*/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to