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

看板RegExp作者 (剁手指了啊~~~)時間12年前 (2012/02/02 10:31), 編輯推噓0(002)
留言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
<A.*?</A>
02/02 10:38, 1F

02/02 10:55, , 2F
謝謝b大~^_^
02/02 10:55, 2F
文章代碼(AID): #1FAVMUdI (RegExp)