S Seth Juarez Nov 21, 2003 #1 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
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
E Eric Gunnerson [MS] Nov 21, 2003 #2 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.
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.
S Seth Juarez Nov 21, 2003 #3 Tha was realy helpful! How would that look programmatically? My Guess: Regex t = new Regex("\*+ (?<Title>.+?) \*+", RegexOptions.Compiled) then what?
Tha was realy helpful! How would that look programmatically? My Guess: Regex t = new Regex("\*+ (?<Title>.+?) \*+", RegexOptions.Compiled) then what?