Regular Expression

  • Thread starter Thread starter Seth Juarez
  • Start date Start date
S

Seth Juarez

I wanted to know how to use regular expressions to pull out values or
strings knowing what set of strings are before and after?

Seth Juarez
 
Generally, what you do is match the pattern before and after, and then
extract from the middle

For example, if you wanted to extract a title from:


****************************** Page 15 of test.doc
*********************************

you would write:

\*+

to match the first part

(?<Title>.+?)

to match the title and

\*+

again to match the end part. So, you'd end up with:

\*+ (?<Title>.+?) \*+

as the whole regex

If you have fixed placeholders before and after, you can simple replace the
"\*+" part of the pattern with the placeholders.
--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://blogs.gotdotnet.com/ericgu/

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Tha was realy helpful!
How would that look programmatically?

My Guess:

Regex t = new Regex("\*+ (?<Title>.+?) \*+", RegexOptions.Compiled)

then what?
 
Back
Top