[問題] 如何抓取一組一組的符合資料
看板RegExp (正規表示式 Regular Expression)作者fantic (剁手指了啊~~~)時間13年前 (2012/02/02 10:31)推噓0(0推 0噓 2→)留言2則, 2人參與討論串1/1
/* 聽說註明使用的語言、環境
* 問題有可能較容易被解決...
*/
我的資料長得像
<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寫法都無法成功~希望大大們幫忙,感謝^^
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.113.169.119
→
02/02 10:38, , 1F
02/02 10:38, 1F
→
02/02 10:55, , 2F
02/02 10:55, 2F
RegExp 近期熱門文章
PTT數位生活區 即時熱門文章