0
我有這樣的HTML代碼中的字符串:拆分HTML鏈接標籤
Hello world
<img src="mypicture.png" />
<p>Some text in a tag</p>
<a href="http://www.google.fr">Link to google</a> Some Text <a href="http://www.yahoo.fr">Link to yahoo</a> End of line
<p>Some text in a tag</p>
<a attribute="some value" href="http://www.apple.com">Link to apple</a>
Some text
我想這個字符串轉換成數組:
0 => Hello world
<img src="mypicture.png" />
<p>Some text in a tag</p>
<a href="
1 => http://www.google.fr
2 => ">Link to google</a> Some Text <a href="
3 => http://www.yahoo.fr
4 => ">Link to yahoo</a> End of line
<p>Some text in a tag</p>
<a attribute="some value" href="
5 => http://www.apple.com
6 => ">Link to apple</a>
Some text
我已經試過這個正則表達式。它工作正常提取的聯繫,但我不設法建立我的陣列...
<a (.*?)href=(.*?)\"(.+?)\"(.*?)>
嘗試樂趣:'(?<= * href = \「)([^」] +)(?= \「[^>] *>) –
with regex.match? – Bob5421
使用'Regex.Split '。 –