我正在使用以下代码块:
<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 to your 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 for Learning"> Earning for 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 for Receipts"> Race for 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 To Shop"> License To 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 and Events"> Sales and 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>
和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>
我正在尝试重写正则表达式模式,因此它会删除所有带有ID的LI!= 1到x值,即60 | 61。想法?
答案 0 :(得分:1)
我对冷融部分的帮助不大,但正则表达并不太难。他们并不总是适合这项工作的工具。
首先,请记住正则表达式不进行数值计算。因此,要执行从56到61的匹配数字之类的操作,您需要使用/(5[6-9]|6[01])/
或/(56|57|58|59|60|61)/
。因此,您需要将数字范围构建为模式。
所以......匹配特定列表项的RE可能是:
/ <li class="standby" id="id${RE}"> .*? <\/LI>/
这使用.*?
,一个“懒星”,扩展到匹配所需的最小可能字符...即</LI>
的下一次出现。使这一点复杂化的是你有嵌套的<UL>
。所以一个懒惰的明星不会总是把你带到正确的地方。
虽然可能可以通过花哨的Perl风格的RE实现这一点,但我认为它不能在扩展RE中实现。我不知道Coldfusion是否理解Perl REs。
您可能希望使用类似XPath的内容来浏览HTML,而不是构建一个大的正则表达式。