问题描述
|
我有一个字符串,里面有一些超链接。我只想将所有链接中的某些链接与正则表达式匹配。我不知道href或类是第一位的,它可能有所不同。
例如,这是一种刺痛:
<div class=\'wp-pagenavi\'>
<span class=\'pages\'>Page 1 of 8</span><span class=\'current\'>1</span>
<a href=\'http://stv.localhost/channel/political/page/2\' class=\'page\'>2</a>
<a href=\'http://stv.localhost/channel/political/page/3\' class=\'page\'>3</a>ccccc<a href=\'http://stv.localhost/channel/political/page/4\' class=\'page\'>4</a><a href=\'http://stv.localhost/channel/political/page/5\' class=\'page\'>5</a><a href=\"http://stv.localhost/channel/political/page/2\" class=\"nextpostslink\">»eee</a><span class=\'extend\'>...</span><a href=\'http://stv.localhost/channel/political/page/8\' class=\'last\'>lastן »</a>
<a class=\"cccc\">xxx</a>
</div>
我只想从aboce字符串中选择具有class nextpostslink的字符串
因此,此示例中的匹配项应返回以下内容-
<a href=\"http://stv.localhost/channel/political/page/2\" class=\"nextpostslink\">»eee</a>
这个正则表达式是我能得到的最接近的-
/<a\\s?(href=)?(\'|\")(.*)(\'|\") class=(\'|\")nextpostslink(\'|\")>.{1,6}<\\/a>/
但是它是从字符串的开头选择链接。
我认为我的问题出在(。*)中,但是我不知道如何更改此设置以仅选择所需的链接。
多谢您的协助。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)