469,640 Members | 1,561 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,640 developers. It's quick & easy.

Extracting text between tags is tricky!

Hello,

Problem:
I want to get the whole text between the opening tag <%OPTIONAL%>
and the closing tag <%/OPTIONAL%>.
The right block is found by (and contains) the placeholder
{#xmreisepop_reisepreistext_1_3#}.

<%OPTIONAL%> and <%/OPTIONAL%> are not allowed to be inside these tags
again.

My first idea was:
<%OPTIONAL%>(.*?){#xmreisepop_reisepreistext_1_3#} (.*?)<%\/OPTIONAL%>

But this does not work with the following peace of text, because it takes
the first <%OPTIONAL%> before and the first
<%/OPTIONAL%> after the placeholder.

<%OPTIONAL%>
....bla bla bla....
<%/OPTIONAL%>
....
<%OPTIONAL%>
....
{#xmreisepop_reisepreistext_1_3#}
....
<%/OPTIONAL%>
Then I tried it with this version:

<%OPTIONAL%>(.*)(?!(<%OPTIONAL%>|<%\/OPTIONAL%>)){#xmreisepop_reisepreistext_1_3#}(.*?) <%\/OPTIONAL%>

No success!
Can someone help me?

Jul 17 '05 #1
5 1557
By the way, I (want to) use regular expressions.

"Lui Ali" <lu********@gmx.de> schrieb im Newsbeitrag
news:2p************@uni-berlin.de...
Hello,

Problem:
I want to get the whole text between the opening tag <%OPTIONAL%>
and the closing tag <%/OPTIONAL%>.
The right block is found by (and contains) the placeholder
{#xmreisepop_reisepreistext_1_3#}.

<%OPTIONAL%> and <%/OPTIONAL%> are not allowed to be inside these tags
again.

My first idea was:
<%OPTIONAL%>(.*?){#xmreisepop_reisepreistext_1_3#} (.*?)<%\/OPTIONAL%>

But this does not work with the following peace of text, because it takes
the first <%OPTIONAL%> before and the first
<%/OPTIONAL%> after the placeholder.

<%OPTIONAL%>
...bla bla bla....
<%/OPTIONAL%>
...
<%OPTIONAL%>
...
{#xmreisepop_reisepreistext_1_3#}
...
<%/OPTIONAL%>
Then I tried it with this version:

<%OPTIONAL%>(.*)(?!(<%OPTIONAL%>|<%\/OPTIONAL%>)){#xmreisepop_reisepreistext_1_3#}(.*?) <%\/OPTIONAL%>

No success!
Can someone help me?

Jul 17 '05 #2
want something like this?

$regex = '|<foo[^<>]*>(?!.*<foo[^<>]*>).*?</foo>|si';
preg_match($regex,$string,$matches);
the above was allows for nested "foo" tags... only matches the
innermost one.. sounded like that's what you wanted..

if you want more than the 1st match.. shoudl use preg_match_all...

BTW, here's a great general regex site:
http://www.regular-expressions.info/

"Lui Ali" <lu********@gmx.de> wrote in message news:<2p************@uni-berlin.de>...
Hello,

Problem:
I want to get the whole text between the opening tag <%OPTIONAL%>
and the closing tag <%/OPTIONAL%>.
The right block is found by (and contains) the placeholder
{#xmreisepop_reisepreistext_1_3#}.

<%OPTIONAL%> and <%/OPTIONAL%> are not allowed to be inside these tags
again.

My first idea was:
<%OPTIONAL%>(.*?){#xmreisepop_reisepreistext_1_3#} (.*?)<%\/OPTIONAL%>

But this does not work with the following peace of text, because it takes
the first <%OPTIONAL%> before and the first
<%/OPTIONAL%> after the placeholder.

<%OPTIONAL%>
...bla bla bla....
<%/OPTIONAL%>
...
<%OPTIONAL%>
...
{#xmreisepop_reisepreistext_1_3#}
...
<%/OPTIONAL%>
Then I tried it with this version:

<%OPTIONAL%>(.*)(?!(<%OPTIONAL%>|<%\/OPTIONAL%>)){#xmreisepop_reisepreistext_1_3#}(.*?) <%\/OPTIONAL%>

No success!
Can someone help me?

Jul 17 '05 #3
hello,

okay, your solution works with my example, but not with my html-template.

It does only find my placeholder when it is inside the last block.

When you test it with my following html-template and the placeholder
{#xmreisepop_reisepreistext_1_3#}
you will get no match, but there should be one.

Regular expression:
<%OPTIONAL%>(?!.*<%OPTIONAL%>)(.*?){#xmreisepop_re isepreistext_1_3#}(.*?)<%\/OPTIONAL%>

html-template:
<td class="cssxmreiseleistehg"><table border="0" cellspacing="0"
cellpadding="0" width="190">

<!-- Titelbild -->

<tr><td class="cssxmreisetitelbild"><ximg src="images/1pixt.gif" width="180"
height="180" alt="" border="0"></td></tr>

<!-- Reisepreis -->

<tr><td class="cssxmreiseleistehead">Reistermin und Preis:</td></tr>

<tr>

<td><table width=100% border="0" cellspacing="0" cellpadding="0">

<%OPTIONAL%>

<tr><td class="cssxmreisepopreisetermin2"
colspan="2">{#xmreisepop_reiseterminvon_1_1#}-{#xmreisepop_reiseterminbis_1_1#}</td></tr>

<tr><td
class="cssxmreisepopreisepreistext"><b>{#xmreisepo p_reisepreistext_1_1#}</b></td></tr>

<tr><td align="right"
class="cssxmreisepopreisepreis"><b>&euro;&nbsp;&nb sp;{#xmreisepop_reisepreis_1_1#}</b></td></tr>

<%/OPTIONAL%>
<%OPTIONAL%>

<tr><td
class="cssxmreisepopreisepreistext">{#xmreisepop_r eisepreistext_1_2#}</td></tr>

<tr><td align="right"
class="cssxmreisepopreisepreis">&euro;&nbsp;&nbsp; {#xmreisepop_reisepreis_1_2#}</td></tr>

<%/OPTIONAL%>
<tr><td
class="cssxmreisepopreisepreistext">{#xmreisepop_r eisepreistext_1_3#}</td></tr>

<%OPTIONAL%>

<tr><td align="right"
class="cssxmreisepopreisepreis">&euro;&nbsp;&nbsp; {#xmreisepop_reisepreis_1_3#}</td></tr>

<%/OPTIONAL%>
<%OPTIONAL%>

<tr><td
class="cssxmreisepopreisepreistext">{#xmreisepop_r eisepreistext_1_4#}</td></tr>

<tr><td align="right"
class="cssxmreisepopreisepreis">&euro;&nbsp;&nbsp; {#xmreisepop_reisepreis_1_4#}</td></tr>
<tr><td colspan="2" class="cssxmreisereiseleistungen"><img src="1pixt.gif"
width="1" height="1" alt="" border="0"></td></tr>

<%/OPTIONAL%>
<!-- -->

<%OPTIONAL%>
<tr><td
class="cssxmreisepopreisepreistext">{#xmreisepop_r eisepreistext_1_3#}</td></tr>

<tr><td class="cssxmreisepopreisetermin2"
colspan="2">{#xmreisepop_reiseterminvon_2_1#}-{#xmreisepop_reiseterminbis_2_1#}</td></tr>

<tr><td
class="cssxmreisepopreisepreistext"><b>{#xmreisepo p_reisepreistext_2_1#}</b></td></tr>

<tr><td align="right"
class="cssxmreisepopreisepreis"><b>&euro;&nbsp;&nb sp;{#xmreisepop_reisepreis_2_1#}</b></td></tr>

<%/OPTIONAL%>
<%OPTIONAL%>

<tr><td
class="cssxmreisepopreisepreistext">{#xmreisepop_r eisepreistext_2_2#}</td></tr>

<tr><td align="right"
class="cssxmreisepopreisepreis">&euro;&nbsp;&nbsp; {#xmreisepop_reisepreis_2_2#}</td></tr>

<%/OPTIONAL%>
<%OPTIONAL%>

<tr><td
class="cssxmreisepopreisepreistext">{#xmreisepop_r eisepreistext_2_3#}</td></tr>

<tr><td align="right"
class="cssxmreisepopreisepreis">&euro;&nbsp;&nbsp; {#xmreisepop_reisepreis_2_3#}</td></tr>

<%/OPTIONAL%>
<%OPTIONAL%>

<tr><td
class="cssxmreisepopreisepreistext">{#xmreisepop_r eisepreistext_2_4#}</td></tr>

<tr><td align="right"
class="cssxmreisepopreisepreis">&euro;&nbsp;&nbsp; {#xmreisepop_reisepreis_2_4#}</td></tr>
<tr><td colspan="2" class="cssxmreisereiseleistungen"><img src="1pixt.gif"
width="1" height="1" alt="" border="0"></td></tr>

<%/OPTIONAL%>
<!-- -->

<%OPTIONAL%>

<tr><td class="cssxmreisepopreisetermin2"
colspan="2">{#xmreisepop_reiseterminvon_3_1#}-{#xmreisepop_reiseterminbis_3_1#}</td></tr>

<tr><td
class="cssxmreisepopreisepreistext"><b>{#xmreisepo p_reisepreistext_3_1#}</b></td></tr>

<tr><td align="right"
class="cssxmreisepopreisepreis"><b>&euro;&nbsp;&nb sp;{#xmreisepop_reisepreis_3_1#}</b></td></tr>

<%/OPTIONAL%>
<%OPTIONAL%>

<tr><td
class="cssxmreisepopreisepreistext">{#xmreisepop_r eisepreistext_3_2#}</td></tr>

<tr><td align="right"
class="cssxmreisepopreisepreis">&euro;&nbsp;&nbsp; {#xmreisepop_reisepreis_3_2#}</td></tr>

<%/OPTIONAL%>
<%OPTIONAL%>

<tr><td
class="cssxmreisepopreisepreistext">{#xmreisepop_r eisepreistext_3_3#}</td></tr>

<tr><td align="right"
class="cssxmreisepopreisepreis">&euro;&nbsp;&nbsp; {#xmreisepop_reisepreis_3_3#}</td></tr>

<%/OPTIONAL%>
<%OPTIONAL%>

<tr><td
class="cssxmreisepopreisepreistext">{#xmreisepop_r eisepreistext_3_4#}</td></tr>

<tr><td align="right"
class="cssxmreisepopreisepreis">&euro;&nbsp;&nbsp; {#xmreisepop_reisepreis_3_4#}</td></tr>
<tr><td colspan="2" class="cssxmreisereiseleistungen"><img src="1pixt.gif"
width="1" height="1" alt="" border="0"></td></tr>

<%/OPTIONAL%>
<!-- -->

<%OPTIONAL%>

<tr><td class="cssxmreisepopreisetermin2"
colspan="2">{#xmreisepop_reiseterminvon_4_1#}-{#xmreisepop_reiseterminbis_4_1#}</td></tr>

<tr><td
class="cssxmreisepopreisepreistext"><b>{#xmreisepo p_reisepreistext_4_1#}</b></td></tr>

<tr><td align="right"
class="cssxmreisepopreisepreis"><b>&euro;&nbsp;&nb sp;{#xmreisepop_reisepreis_4_1#}</b></td></tr>

<%/OPTIONAL%>
<%OPTIONAL%>

<tr><td
class="cssxmreisepopreisepreistext">{#xmreisepop_r eisepreistext_4_2#}</td></tr>

<tr><td align="right"
class="cssxmreisepopreisepreis">&euro;&nbsp;&nbsp; {#xmreisepop_reisepreis_4_2#}</td></tr>

<%/OPTIONAL%>
<%OPTIONAL%>

<tr><td
class="cssxmreisepopreisepreistext">{#xmreisepop_r eisepreistext_4_3#}</td></tr>

<tr><td align="right"
class="cssxmreisepopreisepreis">&euro;&nbsp;&nbsp; {#xmreisepop_reisepreis_4_3#}</td></tr>

<%/OPTIONAL%>
<%OPTIONAL%>

<tr><td
class="cssxmreisepopreisepreistext">{#xmreisepop_r eisepreistext_4_4#}</td></tr>

<tr><td align="right"
class="cssxmreisepopreisepreis">&euro;&nbsp;&nbsp; {#xmreisepop_reisepreis_4_4#}</td></tr>
<tr><td colspan="2" class="cssxmreisereiseleistungen"><img src="1pixt.gif"
width="1" height="1" alt="" border="0"></td></tr>

<%/OPTIONAL%>
<!-- -->

<%OPTIONAL%>

<tr><td class="cssxmreisepopreisetermin2"
colspan="2">{#xmreisepop_reiseterminvon_5_1#}-{#xmreisepop_reiseterminbis_5_1#}</td></tr>

<tr><td
class="cssxmreisepopreisepreistext"><b>{#xmreisepo p_reisepreistext_5_1#}</b></td></tr>

<tr><td align="right"
class="cssxmreisepopreisepreis"><b>&euro;&nbsp;&nb sp;{#xmreisepop_reisepreis_5_1#}</b></td></tr>

<%/OPTIONAL%>
<%OPTIONAL%>

<tr><td
class="cssxmreisepopreisepreistext">{#xmreisepop_r eisepreistext_5_2#}</td></tr>

<tr><td align="right"
class="cssxmreisepopreisepreis">&euro;&nbsp;&nbsp; {#xmreisepop_reisepreis_5_2#}</td></tr>

<%/OPTIONAL%>
<%OPTIONAL%>

<tr><td
class="cssxmreisepopreisepreistext">{#xmreisepop_r eisepreistext_5_3#}</td></tr>

<tr><td align="right"
class="cssxmreisepopreisepreis">&euro;&nbsp;&nbsp; {#xmreisepop_reisepreis_5_3#}</td></tr>

<%/OPTIONAL%>
<%OPTIONAL%>

<tr><td
class="cssxmreisepopreisepreistext">{#xmreisepop_r eisepreistext_5_4#}</td></tr>

<tr><td align="right"
class="cssxmreisepopreisepreis">&euro;&nbsp;&nbsp; {#xmreisepop_reisepreis_5_4#}</td></tr>
<tr><td colspan="2" class="cssxmreisereiseleistungen"><img src="1pixt.gif"
width="1" height="1" alt="" border="0"></td></tr>

<%/OPTIONAL%>
<!-- -->

</table></td>

</tr>

<!-- Leistungen -->

<tr><td class="cssxmreiseleistehead">Leistungen:</td></tr>

<tr><td class="cssxmreisereiseleistungen"><table border="0" cellspacing="0"
cellpadding="0" width="180">

<!-- Nachfolgenden Block markieren für eine Neuformatierung -->

<tr valign="bottom"><td class="cssxmreisereiseleistungen"><ul>

<!-- ###Format1### -->{#xmreise_reiseleistungen#}<!-- ###Format1### -->

</ul></td></tr>
</table></td></tr>

</table></td>

<td>&nbsp;</td>

</tr>

<!-- Reise Ratser -->

<tr>

<td><img src="1pixt.gif" width="30" height="1" alt="" border="0"></td>

<td><img src="1pixt.gif" width="480" height="1" alt="" border="0"></td>

<td><img src="1pixt.gif" width="10" height="1" alt="" border="0"></td>

<td><img src="1pixt.gif" width="190" height="1" alt="" border="0"></td>

<td><img src="1pixt.gif" width="30" height="1" alt="" border="0"></td>

</tr>

</table>

</body>

</html>



_______________________________________________
"Brad Kent" <bk***********@yahoo.com> schrieb im Newsbeitrag
news:7a*************************@posting.google.co m...
want something like this?

$regex = '|<foo[^<>]*>(?!.*<foo[^<>]*>).*?</foo>|si';
preg_match($regex,$string,$matches);
the above was allows for nested "foo" tags... only matches the
innermost one.. sounded like that's what you wanted..

if you want more than the 1st match.. shoudl use preg_match_all...

BTW, here's a great general regex site:
http://www.regular-expressions.info/

"Lui Ali" <lu********@gmx.de> wrote in message
news:<2p************@uni-berlin.de>...
Hello,

Problem:
I want to get the whole text between the opening tag <%OPTIONAL%>
and the closing tag <%/OPTIONAL%>.
The right block is found by (and contains) the placeholder
{#xmreisepop_reisepreistext_1_3#}.

<%OPTIONAL%> and <%/OPTIONAL%> are not allowed to be inside these tags
again.

My first idea was:
<%OPTIONAL%>(.*?){#xmreisepop_reisepreistext_1_3#} (.*?)<%\/OPTIONAL%>

But this does not work with the following peace of text, because it takes
the first <%OPTIONAL%> before and the first
<%/OPTIONAL%> after the placeholder.

<%OPTIONAL%>
...bla bla bla....
<%/OPTIONAL%>
...
<%OPTIONAL%>
...
{#xmreisepop_reisepreistext_1_3#}
...
<%/OPTIONAL%>
Then I tried it with this version:

<%OPTIONAL%>(.*)(?!(<%OPTIONAL%>|<%\/OPTIONAL%>)){#xmreisepop_reisepreistext_1_3#}(.*?) <%\/OPTIONAL%>

No success!
Can someone help me?

Jul 17 '05 #4
Hi,

{#xmreisepop_reisepreistext_1_3#}(?=((?!\<%OPTIONA L%>).)*?\<%\/OPTIONAL%>)

would do that job if PHP would not display: "PHP has encountered a Stack
overflow".......


"Lui Ali" <lu********@gmx.de> schrieb im Newsbeitrag
news:2p************@uni-berlin.de...
hello,

okay, your solution works with my example, but not with my html-template.

It does only find my placeholder when it is inside the last block.

When you test it with my following html-template and the placeholder
{#xmreisepop_reisepreistext_1_3#}
you will get no match, but there should be one.

Regular expression:
<%OPTIONAL%>(?!.*<%OPTIONAL%>)(.*?){#xmreisepop_re isepreistext_1_3#}(.*?)<%\/OPTIONAL%>

html-template:
<td class="cssxmreiseleistehg"><table border="0" cellspacing="0"
cellpadding="0" width="190">

<!-- Titelbild -->

<tr><td class="cssxmreisetitelbild"><ximg src="images/1pixt.gif"
width="180" height="180" alt="" border="0"></td></tr>

<!-- Reisepreis -->

<tr><td class="cssxmreiseleistehead">Reistermin und Preis:</td></tr>

<tr>

<td><table width=100% border="0" cellspacing="0" cellpadding="0">

<%OPTIONAL%>

<tr><td class="cssxmreisepopreisetermin2"
colspan="2">{#xmreisepop_reiseterminvon_1_1#}-{#xmreisepop_reiseterminbis_1_1#}</td></tr>

<tr><td
class="cssxmreisepopreisepreistext"><b>{#xmreisepo p_reisepreistext_1_1#}</b></td></tr>

<tr><td align="right"
class="cssxmreisepopreisepreis"><b>&euro;&nbsp;&nb sp;{#xmreisepop_reisepreis_1_1#}</b></td></tr>

<%/OPTIONAL%>
<%OPTIONAL%>

<tr><td
class="cssxmreisepopreisepreistext">{#xmreisepop_r eisepreistext_1_2#}</td></tr>

<tr><td align="right"
class="cssxmreisepopreisepreis">&euro;&nbsp;&nbsp; {#xmreisepop_reisepreis_1_2#}</td></tr>

<%/OPTIONAL%>
<tr><td
class="cssxmreisepopreisepreistext">{#xmreisepop_r eisepreistext_1_3#}</td></tr>

<%OPTIONAL%>

<tr><td align="right"
class="cssxmreisepopreisepreis">&euro;&nbsp;&nbsp; {#xmreisepop_reisepreis_1_3#}</td></tr>

<%/OPTIONAL%>
<%OPTIONAL%>

<tr><td
class="cssxmreisepopreisepreistext">{#xmreisepop_r eisepreistext_1_4#}</td></tr>

<tr><td align="right"
class="cssxmreisepopreisepreis">&euro;&nbsp;&nbsp; {#xmreisepop_reisepreis_1_4#}</td></tr>
<tr><td colspan="2" class="cssxmreisereiseleistungen"><img src="1pixt.gif"
width="1" height="1" alt="" border="0"></td></tr>

<%/OPTIONAL%>
<!-- -->

<%OPTIONAL%>
<tr><td
class="cssxmreisepopreisepreistext">{#xmreisepop_r eisepreistext_1_3#}</td></tr>

<tr><td class="cssxmreisepopreisetermin2"
colspan="2">{#xmreisepop_reiseterminvon_2_1#}-{#xmreisepop_reiseterminbis_2_1#}</td></tr>

<tr><td
class="cssxmreisepopreisepreistext"><b>{#xmreisepo p_reisepreistext_2_1#}</b></td></tr>

<tr><td align="right"
class="cssxmreisepopreisepreis"><b>&euro;&nbsp;&nb sp;{#xmreisepop_reisepreis_2_1#}</b></td></tr>

<%/OPTIONAL%>
<%OPTIONAL%>

<tr><td
class="cssxmreisepopreisepreistext">{#xmreisepop_r eisepreistext_2_2#}</td></tr>

<tr><td align="right"
class="cssxmreisepopreisepreis">&euro;&nbsp;&nbsp; {#xmreisepop_reisepreis_2_2#}</td></tr>

<%/OPTIONAL%>
<%OPTIONAL%>

<tr><td
class="cssxmreisepopreisepreistext">{#xmreisepop_r eisepreistext_2_3#}</td></tr>

<tr><td align="right"
class="cssxmreisepopreisepreis">&euro;&nbsp;&nbsp; {#xmreisepop_reisepreis_2_3#}</td></tr>

<%/OPTIONAL%>
<%OPTIONAL%>

<tr><td
class="cssxmreisepopreisepreistext">{#xmreisepop_r eisepreistext_2_4#}</td></tr>

<tr><td align="right"
class="cssxmreisepopreisepreis">&euro;&nbsp;&nbsp; {#xmreisepop_reisepreis_2_4#}</td></tr>
<tr><td colspan="2" class="cssxmreisereiseleistungen"><img src="1pixt.gif"
width="1" height="1" alt="" border="0"></td></tr>

<%/OPTIONAL%>
<!-- -->

<%OPTIONAL%>

<tr><td class="cssxmreisepopreisetermin2"
colspan="2">{#xmreisepop_reiseterminvon_3_1#}-{#xmreisepop_reiseterminbis_3_1#}</td></tr>

<tr><td
class="cssxmreisepopreisepreistext"><b>{#xmreisepo p_reisepreistext_3_1#}</b></td></tr>

<tr><td align="right"
class="cssxmreisepopreisepreis"><b>&euro;&nbsp;&nb sp;{#xmreisepop_reisepreis_3_1#}</b></td></tr>

<%/OPTIONAL%>
<%OPTIONAL%>

<tr><td
class="cssxmreisepopreisepreistext">{#xmreisepop_r eisepreistext_3_2#}</td></tr>

<tr><td align="right"
class="cssxmreisepopreisepreis">&euro;&nbsp;&nbsp; {#xmreisepop_reisepreis_3_2#}</td></tr>

<%/OPTIONAL%>
<%OPTIONAL%>

<tr><td
class="cssxmreisepopreisepreistext">{#xmreisepop_r eisepreistext_3_3#}</td></tr>

<tr><td align="right"
class="cssxmreisepopreisepreis">&euro;&nbsp;&nbsp; {#xmreisepop_reisepreis_3_3#}</td></tr>

<%/OPTIONAL%>
<%OPTIONAL%>

<tr><td
class="cssxmreisepopreisepreistext">{#xmreisepop_r eisepreistext_3_4#}</td></tr>

<tr><td align="right"
class="cssxmreisepopreisepreis">&euro;&nbsp;&nbsp; {#xmreisepop_reisepreis_3_4#}</td></tr>
<tr><td colspan="2" class="cssxmreisereiseleistungen"><img src="1pixt.gif"
width="1" height="1" alt="" border="0"></td></tr>

<%/OPTIONAL%>
<!-- -->

<%OPTIONAL%>

<tr><td class="cssxmreisepopreisetermin2"
colspan="2">{#xmreisepop_reiseterminvon_4_1#}-{#xmreisepop_reiseterminbis_4_1#}</td></tr>

<tr><td
class="cssxmreisepopreisepreistext"><b>{#xmreisepo p_reisepreistext_4_1#}</b></td></tr>

<tr><td align="right"
class="cssxmreisepopreisepreis"><b>&euro;&nbsp;&nb sp;{#xmreisepop_reisepreis_4_1#}</b></td></tr>

<%/OPTIONAL%>
<%OPTIONAL%>

<tr><td
class="cssxmreisepopreisepreistext">{#xmreisepop_r eisepreistext_4_2#}</td></tr>

<tr><td align="right"
class="cssxmreisepopreisepreis">&euro;&nbsp;&nbsp; {#xmreisepop_reisepreis_4_2#}</td></tr>

<%/OPTIONAL%>
<%OPTIONAL%>

<tr><td
class="cssxmreisepopreisepreistext">{#xmreisepop_r eisepreistext_4_3#}</td></tr>

<tr><td align="right"
class="cssxmreisepopreisepreis">&euro;&nbsp;&nbsp; {#xmreisepop_reisepreis_4_3#}</td></tr>

<%/OPTIONAL%>
<%OPTIONAL%>

<tr><td
class="cssxmreisepopreisepreistext">{#xmreisepop_r eisepreistext_4_4#}</td></tr>

<tr><td align="right"
class="cssxmreisepopreisepreis">&euro;&nbsp;&nbsp; {#xmreisepop_reisepreis_4_4#}</td></tr>
<tr><td colspan="2" class="cssxmreisereiseleistungen"><img src="1pixt.gif"
width="1" height="1" alt="" border="0"></td></tr>

<%/OPTIONAL%>
<!-- -->

<%OPTIONAL%>

<tr><td class="cssxmreisepopreisetermin2"
colspan="2">{#xmreisepop_reiseterminvon_5_1#}-{#xmreisepop_reiseterminbis_5_1#}</td></tr>

<tr><td
class="cssxmreisepopreisepreistext"><b>{#xmreisepo p_reisepreistext_5_1#}</b></td></tr>

<tr><td align="right"
class="cssxmreisepopreisepreis"><b>&euro;&nbsp;&nb sp;{#xmreisepop_reisepreis_5_1#}</b></td></tr>

<%/OPTIONAL%>
<%OPTIONAL%>

<tr><td
class="cssxmreisepopreisepreistext">{#xmreisepop_r eisepreistext_5_2#}</td></tr>

<tr><td align="right"
class="cssxmreisepopreisepreis">&euro;&nbsp;&nbsp; {#xmreisepop_reisepreis_5_2#}</td></tr>

<%/OPTIONAL%>
<%OPTIONAL%>

<tr><td
class="cssxmreisepopreisepreistext">{#xmreisepop_r eisepreistext_5_3#}</td></tr>

<tr><td align="right"
class="cssxmreisepopreisepreis">&euro;&nbsp;&nbsp; {#xmreisepop_reisepreis_5_3#}</td></tr>

<%/OPTIONAL%>
<%OPTIONAL%>

<tr><td
class="cssxmreisepopreisepreistext">{#xmreisepop_r eisepreistext_5_4#}</td></tr>

<tr><td align="right"
class="cssxmreisepopreisepreis">&euro;&nbsp;&nbsp; {#xmreisepop_reisepreis_5_4#}</td></tr>
<tr><td colspan="2" class="cssxmreisereiseleistungen"><img src="1pixt.gif"
width="1" height="1" alt="" border="0"></td></tr>

<%/OPTIONAL%>
<!-- -->

</table></td>

</tr>

<!-- Leistungen -->

<tr><td class="cssxmreiseleistehead">Leistungen:</td></tr>

<tr><td class="cssxmreisereiseleistungen"><table border="0"
cellspacing="0" cellpadding="0" width="180">

<!-- Nachfolgenden Block markieren für eine Neuformatierung -->

<tr valign="bottom"><td class="cssxmreisereiseleistungen"><ul>

<!-- ###Format1### -->{#xmreise_reiseleistungen#}<!-- ###Format1### -->

</ul></td></tr>
</table></td></tr>

</table></td>

<td>&nbsp;</td>

</tr>

<!-- Reise Ratser -->

<tr>

<td><img src="1pixt.gif" width="30" height="1" alt="" border="0"></td>

<td><img src="1pixt.gif" width="480" height="1" alt="" border="0"></td>

<td><img src="1pixt.gif" width="10" height="1" alt="" border="0"></td>

<td><img src="1pixt.gif" width="190" height="1" alt="" border="0"></td>

<td><img src="1pixt.gif" width="30" height="1" alt="" border="0"></td>

</tr>

</table>

</body>

</html>



_______________________________________________
"Brad Kent" <bk***********@yahoo.com> schrieb im Newsbeitrag
news:7a*************************@posting.google.co m...
want something like this?

$regex = '|<foo[^<>]*>(?!.*<foo[^<>]*>).*?</foo>|si';
preg_match($regex,$string,$matches);
the above was allows for nested "foo" tags... only matches the
innermost one.. sounded like that's what you wanted..

if you want more than the 1st match.. shoudl use preg_match_all...

BTW, here's a great general regex site:
http://www.regular-expressions.info/

"Lui Ali" <lu********@gmx.de> wrote in message
news:<2p************@uni-berlin.de>...
Hello,

Problem:
I want to get the whole text between the opening tag <%OPTIONAL%>
and the closing tag <%/OPTIONAL%>.
The right block is found by (and contains) the placeholder
{#xmreisepop_reisepreistext_1_3#}.

<%OPTIONAL%> and <%/OPTIONAL%> are not allowed to be inside these tags
again.

My first idea was:
<%OPTIONAL%>(.*?){#xmreisepop_reisepreistext_1_3#} (.*?)<%\/OPTIONAL%>

But this does not work with the following peace of text, because it
takes
the first <%OPTIONAL%> before and the first
<%/OPTIONAL%> after the placeholder.

<%OPTIONAL%>
...bla bla bla....
<%/OPTIONAL%>
...
<%OPTIONAL%>
...
{#xmreisepop_reisepreistext_1_3#}
...
<%/OPTIONAL%>
Then I tried it with this version:

<%OPTIONAL%>(.*)(?!(<%OPTIONAL%>|<%\/OPTIONAL%>)){#xmreisepop_reisepreistext_1_3#}(.*?) <%\/OPTIONAL%>

No success!
Can someone help me?


Jul 17 '05 #5
Make sure you're using the "s" modifier so that the "." will match new-lines
also, "{" and "}" are special chars that need escaped.

"Lui Ali" <lu********@gmx.de> wrote in message news:<2p************@uni-berlin.de>...
hello,

okay, your solution works with my example, but not with my html-template.

It does only find my placeholder when it is inside the last block.

When you test it with my following html-template and the placeholder
{#xmreisepop_reisepreistext_1_3#}
you will get no match, but there should be one.

Regular expression:
<%OPTIONAL%>(?!.*<%OPTIONAL%>)(.*?){#xmreisepop_re isepreistext_1_3#}(.*?)<%\/OPTIONAL%>

Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Markus Ernst | last post: by
1 post views Thread by Philippe C. Martin | last post: by
7 posts views Thread by Jasper Bryant-Greene | last post: by
5 posts views Thread by Michael Hill | last post: by
1 post views Thread by Cognizance | last post: by
4 posts views Thread by james.eaton | last post: by
3 posts views Thread by Magnus.Moraberg | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.