Re: Negating a subpattern
| From: | John | Date: | Mon, 12 May 2003 05:03:17 +0000 |
| Subject: | Re: Negating a subpattern | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-147262@lists.php.net to get a copy of this message | ||
Another approach would be to use:
$sections = preg_split ('#(\[template|wordlet .+\])#ism', $your_buffer, -1,
PREG_SPLIT_DELIM_CAPTURE);
produces:
$sections[0] = empty if any matches, $your_buffer otherwise (I think ...)
$sections[1] = "[template a1]"
$sections[2] = "This is a test info" (and whitespace before and after)
$sections[3] = ''[template a2]"
$sections[4] = "This is another info" (and whitespace), etc.
Then you can go back and run elements1, 3, etc., through preg_match() to
pull out your prior subpatterns.
"Acid" <acid@freenet.am> wrote in message
news:002701c317c4$c0f55bc0$6400a8c0@acidxp...
> Hi
>
> I have the following regexp
>
> #\[(template|wordlet) ([^\]]+)\]([^\[]*)#ism
>
> It gives me sections of my configuration file. As I understand it's
> working like find [template or wordlet, then space, then something but ]
> one ore more times, then something but [ zero or more times.
>
> Here is example:
>
> [template a1]
> This is a test info
>
> [template a2]
> This is another info
>
> [wordlet b1]
> Some other stuff goes here.
>
> It works fine as long as under the section I don't have [ or ]. Now I
> want to modify it in order to support square brackets as information
> like this.
>
> [template a1]
> This is another info which contains square brackets like this test[1234]
>
> [template a2...
>
> I tried to search across PHP docs but I didn't found how to describe the
> following expression:
> find [template or wordlet, then space, then something but ] one ore more
> times, then something but [template or [wordlet zero or more times. At
> the same time I want to keep all subpattern boundaries I defined as they
> are in first expression. It seems to me that I can't negate a
> subpattern...
>
> Any help will be appreciated.
>
>
>
>
>
>
>
>