Home  >  Article  >  Backend Development  >  正则表达式 - 如何用php匹配出这段代码?

正则表达式 - 如何用php匹配出这段代码?

WBOY
WBOYOriginal
2016-06-06 20:21:191086browse

有这样一段代码

<code><div>
   <div>
    <span><span>网盘链接: </span> </span> 
    <span><a href="/ntcweb?id=d866a750-9cec-430a-9ea0-5cfbd6a2007a&level=2&pg=webz&uID=thJP9WeIiHG9tvFy&g_ut=2&key=jgf&url=http%3A%2F%2Fwww.%C3%97%C3%97%C3%97%C3%97%C3%97%C3%97%C3%97.com%2Fs%2F1qX18Rky">http://www.×××××××.com/s/1qX18Rky</a> </span> 
   </div> 
   <div></div>
  </div></code>

我想把a标签里的http://www.×××××××.com/s/1qX18Rky匹配出来?
请问正则怎么写?
麻烦不要把

回复内容:

有这样一段代码

<code><div>
   <div>
    <span><span>网盘链接: </span> </span> 
    <span><a href="/ntcweb?id=d866a750-9cec-430a-9ea0-5cfbd6a2007a&level=2&pg=webz&uID=thJP9WeIiHG9tvFy&g_ut=2&key=jgf&url=http%3A%2F%2Fwww.%C3%97%C3%97%C3%97%C3%97%C3%97%C3%97%C3%97.com%2Fs%2F1qX18Rky">http://www.×××××××.com/s/1qX18Rky</a> </span> 
   </div> 
   <div></div>
  </div></code>

我想把a标签里的http://www.×××××××.com/s/1qX18Rky匹配出来?
请问正则怎么写?
麻烦不要把

<code class="php"><?php $text = <<<TEXT
<div>
   <div>
    <span><span>网盘链接: </span> </span>
    <span><a href="/ntcweb?id=d866a750-9cec-430a-9ea0-5cfbd6a2007a&level=2&pg=webz&uID=thJP9WeIiHG9tvFy&g_ut=2&key=jgf&url=http%3A%2F%2Fwww.%C3%97%C3%97%C3%97%C3%97%C3%97%C3%97%C3%97.com%2Fs%2F1qX18Rky">http://www.×××××××.com/s/1qX18Rky</a> </span>
   </div>
   <div></div>
  
TEXT;

preg_match('/<a>]+>([^/', $text, $matches);
print_r($matches);
?></a></code>

<code>/(?]*>)[^)/</code>
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