|
Posted by Fabian Hore on 02/27/06 21:30
Regexp can be pretty brutal for that kind of document parsing.
In direct answer to your question, I'm not sure you can negate a pattern,
only a list of
characters in brakets like so:
'!<#mytag>([^<]+)</#mytag>!'
any '<' character between the tags would break the pattern, but if you stick
to valid HTML
then you shouldn't find that character between tags anyway
allow matched tags to have attributes like so:
'!<#mytag[^>]*>([^<]+)</#mytag>!'
I suggest a look at the Smarty template engine. <smarty.php.net>
--or--
How about defining your own XML markup with two namespaces
<h1>Regular heading</h1>
<tpl:h1>Editable heading</tpl:h1>
-- stuff --
<tpl:p> ... editable paragraph ... </tpl:p>
A custom XML parser routine could do whatever you need when it comes across
your special tags.
I am about to embark on something similar myself
"Paul Renton" <paul.renton@btconnect.com> wrote in message
news:dtvapm$qu4$1@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com...
> Hi,
>
> I'm writing a templating system and everything's going great except for my
> main stumbling block. Regular expressions. d:-(
>
> 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}
>
>
> I hope this makes sense.
>
>
> Many, many thanks in advance.
>
>
> M@
>
Navigation:
[Reply to this message]
|