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 --> #...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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/ |
|
|||
|
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/ |
|
|||
|
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 |