[問題] 如何抓取一組一組的符合資料

作者: fantic (甚麼都會變的...)   2012-02-02 10:31:55
/* 聽說註明使用的語言、環境
* 問題有可能較容易被解決...
*/
我的資料長得像
<A><B>xxxxx1xxx</B></A><A><B>xxxxx2xxx</B></A><A><B>xxxxx3xxx</B></A>
我的寫法(C#)
string input = "<A><B>xxxxx1xxx</B></A><A><B>xxxxx2xxx</B></A><A><B>xxx
xx3xxx</B></A>";
string pattern = @"(<A>.*</A>)"; // 規則字串
Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);
MatchCollection matches = regex.Matches(input); // 將比對後集合傳給 MatchCollection

可是傳回的結果會是一組(原先的資料),我希望可以回傳的結果是有三組符合
分別是 <A><B>xxxxx1xxx</B></A>
<A><B>xxxxx2xxx</B></A>
<A><B>xxxxx3xxx</B></A>
嘗試改了很久的pattern寫法都無法成功~希望大大們幫忙,感謝^^
作者: blackkaku (black)   2012-02-02 10:38:00
<A.*?</A>
作者: fantic (甚麼都會變的...)   2012-02-02 10:55:00
謝謝b大~^_^

Links booklink

Contact Us: admin [ a t ] ucptt.com