【发布时间】:2020-06-06 23:27:42
【问题描述】:
问题的简短直接版本是:为什么这两个正则表达式不同?即,
href=(['"]).+?\1
对
href=(['"]).+?['"] 或 href=(['"]).+?(['"])
我正在这个网站上练习正则表达式,我正在尝试解决这个级别
http://play.inginf.units.it/#/level/6
我将在此处发布全部内容,以防网站将来出现故障。
<tr>
<a href="javascript:openurl('/Xplore/accessinfo.jsp')" class="topUnderlineLinks">
<A href="/iel5/4235/4079606/04079617.pdf?tp=&arnumber=4079617&isnumber=4079606" class="bodyCopy">PDF</A>(3141 KB)
<A href='/xpl/RecentCon.jsp?punumber=10417'>Evolutionary Computation, 2005. The 2005 IEEE Congress on</A><br>
<td width="33%" ><div align="right"> <a href="/xplorehelp/Help_start.html#Help_searchresults.html" class="subNavLinks" target="blank">Help</a> <a href="/xpl/contactus.jsp" class="subNavLinks">Contact
Kimya ile ilgili çeþitli temel referans
<a href="http://search.epnet.com/login.asp?profile=web&defaultdb=geh"
<a href="http://iimpft.chadwyck.com/" target="_parent">International
<a href="standartlar.html#tse" target="_parent">NFPA Standartlarý</a>
<a href="http://www.gutenberg.org/" target="_parent">Project Gutenberg</a>
<a href="http://proquestcombo.safaribooksonline.com/?portal=proquestcombo&uicode=istanbultek"
<a href="http://www.scitation.org" target="_parent">Scitation</a>
dergilerin listesini görmek için <a href="/online/aip.html">bu yolu</a>
<a href="http://www3.interscience.wiley.com/journalfinder.html"
<td width="46%"><a href="/xpl/periodicals.jsp" class="dropDownNav" accesskey="j">Journals & Magazines
<td><a href="http://www.ieee.org/products/onlinepubs/resources/XploreTutorial.pdf" class="dropDownNav">IEEE Xplore Demo</a></td>
| <a href="/xpl/tocalerts_signup.jsp" class="topUnderlineLinks">Alerts</a>
<A href='/xpl/RecentCon.jsp?punumber=10417'>Evolutionary Computation, 2005. The 2005 IEEE Congress on</A><br>
<a href="/search/srchabstract.jsp?arnumber=1554748&isnumber=33079&punumber=10417&k2dockey=1554748@ieeecnfs&query=%28+grammatical+evolution%3Cin%3Eti+%29&pos=9" class="bodyCopy">Abstract</a>
<td><a href="history.jsp">View Session History</a></td>
<td><a href="advsearch.jsp">New Search</a></td>
<a href="http://web5s.silverplatter.com/webspirs/start.ws?customer=kaynak"
<a href="standartlar.html#tse">Türk Standartlarý</a>
<a href="http://isiknowledge.com" target="_parent">Web of Science</a>
<a href='deneme.html#bg'>Butler Group </a>veritabanýna 31 Mart 2007 tarihine kadar deneme eriþimi alýnmýþtýr. <span class="tarih">(19.03.2007)</span>
<a href='deneme.html#ps'>Productscan</a> veritabanýna 31 Mart 2007 tarihine kadar deneme eriþimi alýnmýþtýr. <span class="tarih">(19.03.2007)</span>
我应该匹配这样的文本
href="history.jsp"
即我需要匹配以上文本中的任何href。
现在根据Solutions,似乎答案是href=(['"]).+?\1
但是最后一个反向引用,如果我不使用它并重复正则表达式组(我希望括号称为组,如果我错了,请纠正我),为什么我会得到不同的结果?也就是说,如果我使用它,我会得到错误的结果。 href=(['"]).+?['"] 或 href=(['"]).+?(['"])
【问题讨论】:
-
@Ivar 谢谢,Ivar。其实我只是检查了那个问题。事实上,我在问这个问题之前在那里发表了评论,因为我无法通过查看反向引用的定义来解决这个问题。
-
我正要添加一条额外的评论来解释你的用例,但由于你已经收到了答案,它不会增加太多价值。
标签: regex regex-group backreference