我有一个字符串
<P><A href="http://www.microsoft.com/downloads/details.aspx?FamilyId=39d8f0cd-4043-4eed-bd27-2f26748da664">Microsoft Word 2003 Service Pack 3</A> <BR>(2863866)</P>`
我需要从中获得3个值:
- $value1 = characters between " "
- $value2 = characters between "> </A
- $value3 = characters between ( )
知道如何实现这个目标吗?
答案 0 :(得分:2)
试试正则表达式:
$string = '<P><A href="http://www.microsoft.com/downloads/details.aspx?FamilyId=39d8f0cd-4043-4eed-bd27-2f26748da664">Microsoft Word 2003 Service Pack 3</A> <BR>(2863866)</P>`'
$regex = '"(.*?)">(.*?)<\/A>.*?\((.*?)\)'
if($string -match $regex) {
$Matches[1]
$Matches[2]
$Matches[3]
}
http://www.microsoft.com/downloads/details.aspx?FamilyId=39d8f0cd-4043-4eed-bd27-2f26748da664
Microsoft Word 2003 Service Pack 3
2863866
这将要求所有元素始终存在并且顺序相同(链接,链接名称,parantheses)