You are here: Re: Regular expression that's driving me mad « All PHP « IT news, forums, messages
Re: Regular expression that's driving me mad

Posted by Oli Filth on 02/27/06 21:13

Paul Renton said the following on 27/02/2006 16:53:
> What I'm trying to do is to pick out a starting tag and a finishing tag with
> anything in-between but the finishing tag. For example:
>
> {#my_tag}
> blah blah blah
> {/#my_tag}
>
> However, if there is another instance of this also on the page like:
>
> {#my_tag}
> blah blah blah
> {/#my_tag}
>
> -- Stuff --
>
> {#my_tag}
> blah blah blah
> {/#my_tag}
>
> I don't want the regex to use the start of the first block and the end of
> the second because that would cut out everything in between.
>
> So what I'm looking for is something similar to:
>
> {#tag_name}[anything that doesn't contain {/#tag_name}]{/#tag_name}
>

If you have a regex of the form:

STUFF.*STUFF

then any "STUFF"s in-between will get swallowed by the .*.

However, if you do:

STUFF.*?STUFF

then the * is made un-greedy, i.e. it swallows as little as possible.


--
Oli

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация