Regular Expression

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Dear all,

What is the correct regular expression for reading the following records one
by one?

… header information ….
<R>…..rec 1 …….</R>
<R>…..rec 2 ……………………..</R>
<R>…..rec 3 …….</R>
<R>…..rec 4 ………….</R>
<R>…..rec 5 …….</R>
… trailer information ….


I use

Regex fRec = new Regex("(?<rec><R>[\W\w\s]*</R>)");
Match m;

for (m=fRec.Match(fileContents); m.Success; m=m.NextMatch())
{
System.Diagnostics.Debug.WriteLine(m.Result("${rec}"));
}

However, the first match result m.Result("${rec}") show me all records. Can
anyone tell me how to fix it?

Thanks for any help!

Tedmond
 
I found a way

(?<rec><R>(.*?)</R>)

it works for me in this case. Is there any better solution anyway?

Thanks!
 
Back
Top