繁体   English   中英

PHP中的正则表达式忽略

[英]Regular expression ignore in PHP

例如,有这行:

<a title="best title in the world" href="http://website.com/15661-erko-rhyno/">! Erko_Rhyno !</a>

现在我的代码返回:

15661-erko-rhyno/">! Erko_Rhyno !

我正在使用:

(?<=\<strong\>\<a title\=\"best title in the world\" href\=\"http:\/\/www\.website\.com\/web\/index\.php\/user\/).*?(?=\<\/a\>\<\/strong\>)

现在,我需要没有15661-erko-rhyno/">像这样:

! Erko_Rhyno !

我知道为什么它返回15661-erko-rhyno/">因为我指定仅忽略此部分:

<strong><a title="best title in the world" href="http://www.webste.com/web/index.php/user/

但是现在出现问题了,您可以看到以下部分:

15661-erko-rhyno/">` 

总是会变化,而且我不知道如何忽略这一部分,我将重复自己的操作,并再次提供我为忽略不需要的字符而要求的代码:

(?<=\<strong\>\<a title\=\"best title in the world\" href\=\"http:\/\/www\.website\.com\/web\/index\.php\/user\/).*?(?=\<\/a\>\<\/strong\>)

也许有人可以提供示例或回答我应该写些什么,以便忽略这些行剩下的内容?

只需忽略>字符,例如

\>([^\>]+)\<\/a\>

得到! Erko_Rhyno ! ! Erko_Rhyno ! 在组(1)中

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM