Home > Article > Backend Development > Please tell me how to modify this regular expression.
Dear experts, please tell me how to write a regular expression. Grab a piece of content from a web page:
<code><div class="location fl"> <span class="fl">商家地址:</span><span class="fl info-detail">北京市朝阳区亚运村阳光广场北门对面</span> </div></code>
The regex I wrote is:
<code>"<div class=\"location fl\">\s*?<span class=\"fl\">.*?</span><span class=\"fl info - detail\">(.*?)</span>\s*?</div>"</code>
It can pass on the regular expression tester, but the result cannot be obtained on PHP. How should it be modified?
Dear experts, please tell me how to write a regular expression. Grab a piece of content from a web page:
<code><div class="location fl"> <span class="fl">商家地址:</span><span class="fl info-detail">北京市朝阳区亚运村阳光广场北门对面</span> </div></code>
The regex I wrote is:
<code>"<div class=\"location fl\">\s*?<span class=\"fl\">.*?</span><span class=\"fl info - detail\">(.*?)</span>\s*?</div>"</code>
It can pass on the regular expression tester, but the result cannot be obtained on PHP. How should it be modified?
Using xpath, it can be solved. "//div//span[contains(@class,'info-detail')]/text()[1]"
Continue to find out how to write regular expressions.