Jump to content

[SOLVED] Regular Expression Help


Recommended Posts

Let's say i have this code:

$sHTML = '<TABLE id=_ctl0_NavBar cellSpacing=0 cellPadding=0 width="100%">'
$sHTML = $shtml & '<TBODY>'&@CRLF
$sHTML = $shtml & '<TR>'&@CRLF
$sHTML = $shtml & '<TD width=3><IMG style="HEIGHT: 1px" alt="" src="D:\Documents and Settings\Administrator\Desktop\btc\images/spacer.gif" border=0></TD>'&@CRLF
$sHTML = $shtml & '<TD class=NavBar_TabOn noWrap align=middle width=120 height=22><A class=navbar_links href="D:\Documents and Settings\Administrator\Desktop\btc\default.aspx">Browse</A></TD>'&@CRLF
$sHTML = $shtml & '<TD width=1><IMG style="HEIGHT: 1px" alt="" src="D:\Documents and Settings\Administrator\Desktop\btc\images/spacer.gif" border=0></TD>'&@CRLF
$sHTML = $shtml & '<TD class=NavBar_TabOff noWrap align=middle width=120 height=22><A class=navbar_links href="D:\Documents and Settings\Administrator\Desktop\btc\search.aspx">Search</A></TD>'&@CRLF
$sHTML = $shtml & '<TD width=1><IMG style="HEIGHT: 1px" alt="" src="D:\Documents and Settings\Administrator\Desktop\btc\images/spacer.gif" border=0></TD>'&@CRLF
$sHTML = $shtml & '<TD class=NavBar_TabOff noWrap align=middle width=120 height=22><A class=navbar_links href="D:\Documents and Settings\Administrator\Desktop\btc\logout.aspx">Logout</A></TD>'&@CRLF
$sHTML = $shtml & '<TD width=1><IMG style="HEIGHT: 1px" alt="" src="D:\Documents and Settings\Administrator\Desktop\btc\images/spacer.gif" border=0></TD>'&@CRLF
$sHTML = $shtml & '<TD class=NavBar_TabOff noWrap align=middle width=120 height=22><A class=navbar_links href="D:\Documents and Settings\Administrator\Desktop\btc\admin/login.aspx">Admin</A></TD>'&@CRLF
$sHTML = $shtml & '<TD width="90%"><IMG style="HEIGHT: 1px" alt="" src="D:\Documents and Settings\Administrator\Desktop\btc\images/spacer.gif" border=0></TD></TR>'&@CRLF
$sHTML = $shtml & '<TR>'&@CRLF
$sHTML = $shtml & '<TD bgColor=#7898b5 height=1></TD>'&@CRLF
$sHTML = $shtml & '<TD bgColor=#ffffff height=1></TD>'&@CRLF
$sHTML = $shtml & '<TD bgColor=#7898b5 height=1></TD>'&@CRLF
$sHTML = $shtml & '<TD bgColor=#7898b5 height=1></TD>'&@CRLF
$sHTML = $shtml & '<TD bgColor=#7898b5 height=1></TD>'&@CRLF
$sHTML = $shtml & '<TD bgColor=#7898b5 height=1></TD>'&@CRLF
$sHTML = $shtml & '<TD bgColor=#7898b5 height=1></TD>' &@CRLF
$sHTML = $shtml & '<TD bgColor=#7898b5 height=1></TD>'&@CRLF
$sHTML = $shtml & '<TD bgColor=#7898b5 height=1></TD></TR></TBODY></TABLE>'&@CRLF
$sHTML = $shtml & 'asdf'

;- /////////////////// REGEX TO REPLACE THE ENTIRE TABLE /////////////////////////
$text = StringRegExpReplace($sHTML, '<TABLE id=_ctl0_NavBar(.*?)></TABLE>', " ")
;- ////////////////END REGEX TO REPLACE THE ENTIRE TABLE /////////////////////////

MsgBox(0, "title", $text)

I for the life of me, cannot figure out how to actually get it to remove the entire table. I don't know for sure if it's CRLF's or LF's or just CR's, they are just there as an example.

How can i accomplish that?

Edited by zackrspv

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Link to comment
Share on other sites

$text = StringRegExpReplace($sHTML, '(?i)\<TABLE id=_ctl0_NavBar[\D\d]+\<\/TABLE>', "")

sweet,

While trying to figure it out:

$text = StringRegExpReplace($sHTML, '<TABLE id=_ctl0_NavBar(.*?)>(?s)(.*?)(?s)</TABLE>', " ")

also seems to work. :)

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...