Regular Expression for finding specific text in a document
-
Friday, July 03, 2009 11:41 AM
I have the below format of text in a document :
ECO [ECO-xxxxx] : Cover Page
here the number xxxxx changes and the rest remains the same. Also I need to exclude the text which is in the format
ECO [ECO-xxxxx] : Cover Page (continued)
Desperately looking for some help as I am new to this area.
Thanks much,
Tanya Sharma
All Replies
-
Friday, July 03, 2009 1:45 PM
You can use
^\s*ECO \[ECO-[0-9]*\] : Cover Page\s*$
Make sure you use the RegexOptions.Multiline option.
using System; using System.Text.RegularExpressions; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string textSource = "Introduction ...\n"+ "ECO [ECO-00012] : Cover Page\n"+ "Some text here ...\n"+ "ECO [ECO-xxxxx] : Cover Page (continued)\n" + "Some more text ..."; MatchCollection ms = Regex.Matches(textSource, "^\\s*ECO \\[ECO-[0-9]*\\] : Cover Page\\s*$", RegexOptions.Multiline); foreach (Match m in ms) { Console.WriteLine(m.Value); } } } } -
Monday, July 06, 2009 9:48 AMHi Mumba, Thanks for your reply however I am still unable to get what I wanted. I have a PDF with all such headers which I need to select using a PDF splitter. This PDF splitter takes regular expressions which are perl combatible to select a part of the text. I tried the code you mentioned however it did not work. Btw, the name of the splitter is Auto Split Pro Plug in. Let me know if you have any ideas. Regards, Tanya
-
Monday, July 06, 2009 3:15 PM
Here's a link to the Perl Regular Expression syntax.
http://www.perl.com/doc/manual/html/pod/perlre.html
Read up and then try this modification to Mumba's post...
/\bECO \[ECO-\d*\]:\s*Cover Page/
You should try shortening the expression until you find something, then build up until you find exactly what you want. Learn as you go. For example...
/ECO/
then
/\bECO/
then
/\bECO\s*\[/
etc...
Perl style uses the / ... / to bound their expression strings. I never use Perl and I don't have Auto Split Pro, so others may be able to offer more and better help.
Les Potter, Xalnix Corporation, Yet Another C# Blog- Proposed As Answer by JohnGrove Tuesday, July 07, 2009 7:41 PM

