Regex 'group' syntax

  • Thread starter Thread starter Richard.Haggard
  • Start date Start date
R

Richard.Haggard

Guest
I'm trying to use Regex to find a substring. Here's an example of the source string:

<MarkupSummary Version="1.0" Document="E2576_1.pdf">

What I want to do is to extract the E2576_1.pdf substring but just can't get it right.


Regex rx = new Regex("Document=\"" + @"(\w+<docName>)" + "\"", RegexOptions.Compiled);
Match match = rx.Match(fileContents);
if (!match.Success)
// Do error stuff.
else
FileSource = match.Groups["docName"].Value;




What should the syntax be?

As an aside, I am sorely reminded of the old programmer's saying, "If you have a problem and try to solve it with Regex then you'll end up with two problems."




Richard Lewis Haggard

Continue reading...
 
Back
Top