Home  >  Article  >  Backend Development  >  Please tell me how to modify this regular expression.

Please tell me how to modify this regular expression.

WBOY
WBOYOriginal
2016-12-01 01:27:21927browse

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?

Reply content:

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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn