regular expression

This is a discussion on regular expression within the PHP Language forums, part of the PHP Programming Forums category; I am having a very difficult time finding a regular expression to match the following pattern #1: <!-- someword --> #...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 06-27-2004
Jeremy Shovan
 
Posts: n/a
Default regular expression

I am having a very difficult time finding a regular expression to match
the following pattern

#1: <!-- someword -->
#2: <!-- someword_end -->

I need a regular expression that will match #1 but not #2. Any one got
any ideas?

Jeremy Shovan
Reply With Quote
  #2 (permalink)  
Old 06-27-2004
Marian Heddesheimer
 
Posts: n/a
Default Re: regular expression

On Sun, 27 Jun 2004 03:29:37 -0700, Jeremy Shovan
<jeremys013@foundationx.com> wrote:

>#1: <!-- someword -->
>#2: <!-- someword_end -->
>
>I need a regular expression that will match #1 but not #2. Any one got
>any ideas?


$test1 = "<!-- someword -->";
$test2 = "<!-- someword_end -->";
$pattern = "/<!-- someword -->/";
echo "test1: " . preg_match($pattern, $test1) . "<br>";
echo "test2: " . preg_match($pattern, $test2) . "<br>";

Regards

Marian

--
Tipps und Tricks zu PHP, Coaching und Projektbetreuung
http://www.heddesheimer.de/coaching/
Reply With Quote
  #3 (permalink)  
Old 06-27-2004
Marian Heddesheimer
 
Posts: n/a
Default Re: regular expression

On Sun, 27 Jun 2004 03:29:37 -0700, Jeremy Shovan
<jeremys013@foundationx.com> wrote:

>#1: <!-- someword -->
>#2: <!-- someword_end -->
>
>I need a regular expression that will match #1 but not #2. Any one got
>any ideas?


if you want to find out what "someword" really is:

$test1 = "<!-- someword -->";
$test2 = "<!-- someword_end -->";
$pattern = "/<!-- ([^_]*) -->/";
echo "test1: " . preg_match($pattern, $test1, $ary) . "<br>";
print_r($ary);
echo "test2: " . preg_match($pattern, $test2, $ary) . "<br>";

Regards

Marian

--
Tipps und Tricks zu PHP, Coaching und Projektbetreuung
http://www.heddesheimer.de/coaching/
Reply With Quote
  #4 (permalink)  
Old 06-27-2004
Jeremy Shovan
 
Posts: n/a
Default Re: regular expression

Marian Heddesheimer wrote:

> On Sun, 27 Jun 2004 03:29:37 -0700, Jeremy Shovan
> <jeremys013@foundationx.com> wrote:
>
>
>>#1: <!-- someword -->
>>#2: <!-- someword_end -->
>>
>>I need a regular expression that will match #1 but not #2. Any one got
>>any ideas?

>
>
> if you want to find out what "someword" really is:
>
> $test1 = "<!-- someword -->";
> $test2 = "<!-- someword_end -->";
> $pattern = "/<!-- ([^_]*) -->/";
> echo "test1: " . preg_match($pattern, $test1, $ary) . "<br>";
> print_r($ary);
> echo "test2: " . preg_match($pattern, $test2, $ary) . "<br>";
>
> Regards
>
> Marian
>


Go figure I can work on this for 3 hours and then as soon as I ask for
help I figure it out. Here is the finished product:

return
preg_replace_callback("/(<\s*\/td\s*>\s*)?(<\s*\/tr\s*>\s*)?(<\s*\/table\s*>\s*)?(<!--\s*.*\s*\/\/\s*--\s*\>\s*)(<\s*table(.*?)>\s*)?(<\s*tr(.*?)>\s*)?(< \s*td(.*?)>\s*)?/","checkForEnd",$sting);

function checkForEnd($string){
if(strstr($string[4],"_end")){
return
"</td></tr></table>\n".$string[4].$string[5].$string[7].$string[9];
}else{
return
$string[1].$string[2].$string[3].$string[4]."<table".$string[6]."><tr".$string[8]."><td".$string[10].">";
}
}

Jeremy Shovan
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 12:50 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0