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

Please tell me how to modify this regular expression.

WBOY
Release: 2023-03-02 10:16:02
Original
955 people have browsed it

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>
Copy after login
Copy after login

The regex I wrote is:

<code>"<div class=\"location fl\">\s*?<span class=\"fl\">.*?</span><span class=\"fl info - detail\">(.*?)</span>\s*?</div>"</code>
Copy after login
Copy after login

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>
Copy after login
Copy after login

The regex I wrote is:

<code>"<div class=\"location fl\">\s*?<span class=\"fl\">.*?</span><span class=\"fl info - detail\">(.*?)</span>\s*?</div>"</code>
Copy after login
Copy after login

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.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template