有关正则表达式问题,请高手解答

丰圣谋 发布于 2013/12/27 16:04
阅读 433
收藏 1

以下为一段文本:

<p>All the slots game in slotsmamma.com are free and just play for fun. We work on these slot machines as a labor of love, with the hopes that people will find it useful, and in turn share it with their own friends and family. We welcome you to join us to test the new online slots, <a href="/dinosaur/">Jurassic Park</a>, <a href="/penny-slots/">Penny Slots</a>, <a href="/loose-slots/">Loose Slots</a>, <a href="/super-slots/">Super Slot o bot</a>, <a href="/cash-cruiser/">Cash Cruiser</a>, <a href="/million-dollar-rally/">Million Dollar Rally</a>, <a href="/jungle-adventures/">Jungle Adventures Slots</a>, <a href="/snow-mountain/">Snow Mountain Slot</a>,  or ourfirst <a href="/bonus/">Bonus Slots</a>.dfdf</p>

要求是取出a标签并左右两边的字符,例:

左边文本<a href="aaa">dfdfdf</a>右边文本

以下是我提出的内容,有一段不对,不知怎整。

All the slots game in slotsmamma.com are free and just play for fun. We work on these slot machines as a labor of love, with the hopes that people will find it useful, and in turn share it with their own friends and family. We welcome you to join us to test the new online slots, <a href="/dinosaur/">Jurassic Park</a>,
<a href="/penny-slots/">Penny Slots</a>,
<a href="/loose-slots/">Loose Slots</a>,
<a href="/super-slots/">Super Slot o bot</a>,
<a href="/cash-cruiser/">Cash Cruiser</a>,
<a href="/million-dollar-rally/">Million Dollar Rally</a>,
<a href="/jungle-adventures/">Jungle Adventures Slots</a>,
<a href="/snow-mountain/">Snow Mountain Slot</a>,  or ourfirst
<a href="/bonus/">Bonus Slots</a>.dfdf


问题是:<a href="/bonus/">Bonus Slots</a>.dfdf 这段的左边没有字符串

正确应该是:,  or ourfirst<a href="/bonus/">Bonus Slots</a>.dfdf

以下是我的正则:

([^>]*)<a\s([^>\n\s]*)href=(\"|\'|[^\s])?((https|http|\/|\./|\w|\d|_|)(.*?))[\"|\'|^\s][^>]*>(.*?)</a>(([^<])*)


加载中
0
千里草Darin

要求是取出a标签并左右两边的字符,例:文本<a href="aaa">dfdfdf</a>右边文本

楼主的需求我没看明白,你把需要达到的目的结果给贴出来.

0
MrZQ
MrZQ
试试这个呢
\b.*?<a.*?href="(.*?)".*?>.*?</a>



0
freesnow
freesnow

其实你是想按,来分割吧,你为什么不直接split呢?

你还是用正则的话,你是想让每个都是以,结尾吧?

那你试试[^,]+(?:,|(?=<))

0
千里草Darin

引用来自“MyKings”的答案

试试这个呢
\b.*?<a.*?href="(.*?)".*?>.*?</a>



这个取不到</a>右边的字符吧
0
Jackin
Jackin
#([^>]+\<a .+?\</a\>[^<]+)#i
0
丰圣谋
丰圣谋
多谢各位
0
要吃九个橙子
要吃九个橙子
(?<=/a>|^).*?(?=<a|$)

// 以 "/a>" 或者 "^" 开始
// 以 "<a"  或者 "$" 结束
// LZ 看看是不是你想要的.



0
返回顶部
顶部