regex - Removing Code by using rereplace -


hi have following code, using following code remove contents page not know:

i using regex, , cannot use jsoup, please not provide jsoup link or code because useless use here me..

<cfset removetitle = rereplacenocase(cfhttp.filecontent, '<title[^>]*>(.+)</title>', "\1")> 

now above same way, want use follwoing things:

1. <base href="http://search.google.com"> 2. <link rel="stylesheet" href="mystyle.css"> 3. , there 5 tables inside body, want remove 2nd table., 

can guide on

scott right, , leigh right before, when asked similar question, jsoup best option.

as regex solution. possible regex there problems regex cannot solve. instance, if first or second table contains nested table, regex trip. (note text not required between tables, i'm demonstrating things can between tables)

(if there nested table, regex can handle it, if there nested table, in other words: unknown), gets lot messier.)

<cfsavecontent variable="sampledata"> <body> <table cellpadding="4"></table>stuff <table border="5" cellspacing="7"></table>between <table border="3"></table>the <table border="2"></table>tables <table></table> </body> </cfsavecontent>  <cfset sampledata = rereplace(sampledata,"(?s)(.*?<table.*?>.*?<\/table>.*?)(<table.*?>.*?<\/table>)(.*)","\1\3","all") /> <cfoutput><pre>#htmleditformat(sampledata)#</pre></cfoutput> 

what is

(?s) sets . match newlines well. (.*?<table.*?>.*?<\/table>.*?) matches before first table, first table, , between , second table , sets capture group 1. (<table.*?>.*?<\/table>) matches second table , creates capture group 2. (.*) matches after second table , creates capture group 3.

and third paramters \1\3 picks first , third capture groups.

if have control of source document, can create html comments like

<!-- table1 -->   <table>...</table> <!-- /table1 --> 

and use in regex , end more regex-friendly document.

however, still, scott said best, not using proper tool task is:

that telling carpenter, build me house, don't use hammer.

these tools created because programmers run precisely problem you're having, , create tool, , freely share it, because job better.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -