coldfusion - regex to remove menu items from string -
i working following code block:
<ul id="nav-main-links"> <li class="standby" id="id61"> <a href="/?event=user.home.dsphome" target="_self" title="admin tools"> admin tools<font class="menuitemtype">(cb)</font> </a> <ul class="sub-nav-main-links nestinglevel1"> <li class="standby" id="id62"> <a href="/unsecured/sitesurvey.cfm" target="_blank" title="site survey"> site survey<font class="menuitemtype">(x)</font> </a> </li></ul></li> <li class="standby" id="id57"> <a href="/?event=mall.information.dspinformation" target="_self" title="mall info"> mall info<font class="menuitemtype">(cb)</font> </a> </li> <li class="standby" id="id19"> <a href="/?event=sms.smsbroadcast.browsesmsbroadcasts" target="_self" title="send sms text messages groups"> sms<font class="menuitemtype">(cb)</font> </a> <ul class="sub-nav-main-links nestinglevel1"> <li class="standby" id="id58"> <a href="/?event=sms.smsgroup.browsesmsgroups" target="_self" title="sms groups"> groups<font class="menuitemtype">(cb)</font> </a> </li> <li class="standby" id="id59"> <a href="/?event=sms.smskeyword.browsesmskeywords" target="_self" title="sms keywords"> keywords<font class="menuitemtype">(cb)</font> </a> </li></ul></li> <li class="standby" id="id56"> <a href="/?event=mall.directory.dsplist" target="_self" title="directory"> directory<font class="menuitemtype">(cb)</font> </a> <ul class="sub-nav-main-links nestinglevel1"> <li class="standby" id="id35"> <a href="/?event=mall.directory.dspadd" target="_self" title="add new"> add new<font class="menuitemtype">(cb)</font> </a> </li></ul></li> <li class="standby" id="id2"> <a href="/admin2/mall/mallinfo.cfm" target="_self" title="mall info"> mall info<font class="menuitemtype">(l)</font> </a> <ul class="sub-nav-main-links nestinglevel1"> <li class="standby" id="id17"> <a href="/sidefeature" target="_self" title="side features"> side features<font class="menuitemtype">(l)</font> </a> </li> <li class="standby" id="id18"> <a href="/admin2/misc/lakeelsinore/homepage.cfm" target="_self" title="edit homepage"> edit homepage<font class="menuitemtype">(l)</font> </a> </li></ul></li> <li class="standby" id="id22"> <a href="/events/index.cfm" target="_self" title="events"> events<font class="menuitemtype">(l)</font> </a> <ul class="sub-nav-main-links nestinglevel1"> <li class="standby" id="id23"> <a href="/admin2/bdayclub/index.cfm" target="_self" title="birthday club"> birthday club<font class="menuitemtype">(l)</font> </a> </li> <li class="standby" id="id24"> <a href="/admin2/misc/12days.cfm" target="_self" title="12 days points"> 12 days points<font class="menuitemtype">(l)</font> </a> </li> <li class="standby" id="id25"> <a href="/admin2/darksite/dsform.cfm" target="_self" title="emergency info"> emergency info<font class="menuitemtype">(l)</font> </a> </li> <li class="standby" id="id26"> <a href="/admin2/mnog/mnog.cfm" target="_self" title="mnog"> mnog<font class="menuitemtype">(l)</font> </a> </li> <li class="standby" id="id27"> <a href="/admin2/mnog/eforl.cfm" target="_self" title="earning learning"> earning learning<font class="menuitemtype">(l)</font> </a> </li> <li class="standby" id="id28"> <a href="/admin2/partners/partners.cfm" target="_self" title="partners"> partners<font class="menuitemtype">(l)</font> </a> </li> <li class="standby" id="id29"> <a href="/admin2/events/raceforreceipts.cfm" target="_self" title="race receipts"> race receipts<font class="menuitemtype">(l)</font> </a> </li></ul></li> <li class="standby" id="id30"> <a href="/admin2/mall/mallhours.cfm" target="_self" title="hours"> hours<font class="menuitemtype">(l)</font> </a> </li> <li class="standby" id="id31"> <a href="/admin2/mall/dir/" target="_self" title="directory"> directory<font class="menuitemtype">(l)</font> </a> </li> <li class="standby" id="id32"> <a href="https://www.google.com/accounts/login" target="_self" title="google analytics"> google analytics<font class="menuitemtype">(x)</font> </a> </li> <li class="standby" id="id33"> <a href="/admin2/mall/fpurl/poolb.cfm" target="_self" title="i-features"> i-features<font class="menuitemtype">(l)</font> </a> </li> <li class="standby" id="id34"> <a href="/admin2/mall/fpurl/pressreleaseurban.cfm" target="_self" title="press releases"> press releases<font class="menuitemtype">(l)</font> </a> </li> <li class="standby" id="id36"> <a href="/admin2/store/retailernav.cfm" target="_self" title="retail"> retail<font class="menuitemtype">(l)</font> </a> <ul class="sub-nav-main-links nestinglevel1"> <li class="standby" id="id37"> <a href="/admin2/coupons/coupondirect.cfm" target="_self" title="coupons"> coupons<font class="menuitemtype">(l)</font> </a> </li> <li class="standby" id="id38"> <a href="/storeoffers/" target="_self" title="license shop"> license shop<font class="menuitemtype">(l)</font> </a> </li> <li class="standby" id="id39"> <a href="/admin2/jobs-old/old/jobadmin.cfm" target="_self" title="jobs"> jobs<font class="menuitemtype">(l)</font> </a> </li> <li class="standby" id="id40"> <a href="/admin2/store/modstore.cfm?mode=sales" target="_self" title="sales , events"> sales , events<font class="menuitemtype">(l)</font> </a> </li> <li class="standby" id="id41"> <a href="/admin2/mdb/" target="_self" title="mdb data"> mdb data<font class="menuitemtype">(l)</font> </a> </li> <li class="standby" id="id42"> <a href="http://mdb2.mallfinder.com/retail%20hub/" target="_self" title="mdb application"> mdb application<font class="menuitemtype">(x)</font> </a> </li> <li class="standby" id="id43"> <a href="/admin2/mdb/reports/index.cfm" target="_self" title="swipe reports"> swipe reports<font class="menuitemtype">(l)</font> </a> </li> <li class="standby" id="id44"> <a href="/admin2/mallslideshows.cfm" target="_self" title="slide shows"> slide shows<font class="menuitemtype">(l)</font> </a> </li></ul></li> <li class="standby" id="id45"> <a href="/email/epostcard.cfm" target="_self" title="email"> email<font class="menuitemtype">(l)</font> </a> <ul class="sub-nav-main-links nestinglevel1"> <li class="standby" id="id46"> <a href="/email/admemail.cfm" target="_self" title="admemail"> admemail<font class="menuitemtype">(l)</font> </a> </li> <li class="standby" id="id47"> <a href="/email/ddrepostcard.cfm" target="_self" title="ddr email"> ddr email<font class="menuitemtype">(l)</font> </a> </li> <li class="standby" id="id48"> <a href="/email/epnew.cfm" target="_self" title="new email"> new email<font class="menuitemtype">(l)</font> </a> </li> <li class="standby" id="id50"> <a href="/email/emailreport.cfm" target="_self" title="email report"> email report<font class="menuitemtype">(l)</font> </a> </li> <li class="standby" id="id51"> <a href="/directmail/index.cfm" target="_self" title="direct mail"> direct mail<font class="menuitemtype">(l)</font> </a> </li> <li class="standby" id="id52"> <a href="/workflow/workflow_entryform.cfm" target="_self" title="change orders"> change orders<font class="menuitemtype">(l)</font> </a> </li></ul></li> <li class="standby" id="id53"> <a href="/contactus.cfm" target="_self" title="contacts"> contacts<font class="menuitemtype">(l)</font> </a> <ul class="sub-nav-main-links nestinglevel1"> <li class="standby" id="id54"> <a href="http://vendor1.retailhub.com/index.cfm" target="_self" title="ven"> ven<font class="menuitemtype">(x)</font> </a> </li> <li class="standby" id="id55"> <a href="/sponsorship/spevents.cfm" target="_self" title="sponsorship"> sponsorship<font class="menuitemtype">(l)</font> </a> </li></ul></li></ul>
and following pseudo block in cfml:
<cfscript> mydisplay=structnew(); mydisplay.pseudo=pseudo; mydisplay.idstoremove="60|61"; mydisplay.regextestpattern='<li[^>]*?!id="id(' & mydisplay.idstoremove & ')".*?li>'; mydisplay.menu=rereplacenocase(mydisplay.pseudo,mydisplay.regextestpattern,"","all"); </cfscript>
i trying rework regex pattern removes lis ids != 1 x values i.e. 60|61. ideas?
i can't coldfusion part of this, regular expression aren't hard. they're not right tool job.
first off, remember regular expressions don't numeric evaluations. match numbers 56 61, you'd need use /(5[6-9]|6[01])/
or /(56|57|58|59|60|61)/
. you'll need construct number ranges patterns.
so... re matches particular list item might be:
/ <li class="standby" id="id${re}"> .*? <\/li>/
this uses .*?
, "lazy star" expands minimum possible characters required match ... i.e. next occurrence of </li>
. thing complicates have nested <ul>
s. lazy star won't right place.
while might possible achieve fancy perl-style re, don't think can achieved in extended re. don't know if coldfusion understands perl res.
you might want explore using xpath walk through html, instead of building big gnarly regular expression.
Comments
Post a Comment