tags:

views:

58

answers:

2

I want to parse out each modified file that is reported during FCIV's verification process.

It comes out like this:

"Microsoft Windows XP [Version 5.1.2600]\r\n(C) Copyright 1985-2001 Microsoft Corp.\r\n\r\nC:\MD5Checksum>C:\MD5Checksum\fciv.exe -v -xml db.xml\r\n//\r\n// File Checksum Integrity Verifier version 2.05.\r\n//\r\nStarting checksums verification : 09/10/2009 at 11h19'30\r\r\n\r\r\nList of modified files:\r\r\n-----------------------\r\r\nc:\md5checksum\readme.txt \r\r\n\tHash is\t\t: e2c6d562bd35352b73c00a744e9c07c6\r\r\n\tIt should be\t: 79ac8d043dc8739f661c45cc33fc07ac\r\r\n\r\nc:\md5checksum\fciv.exe \r\r\n\tHash is\t\t: 79ac8d043dc8739f661c45cc33fc07ac\r\r\n\tIt should be\t: e2c6d562bd35352b73c00a744e9c07c6\r\r\n\r\n\r\r\nEnd Verification : 09/10/2009 at 11h19'30\r\r\n\r\r\n\r\nC:\MD5Checksum>"

Right now I'm using this as the Regex (which works fine), but I'm wondering if there is a simpler way?

".*(\r\r\n\t)(Hash)( )(is)[\t]{2}(:)( )[a-zA-Z0-9]{32}(\r\r\n\t)(It)( )(should)( )(be)[\t](:)( )[a-zA-Z0-9]{32}"
+1  A: 

I suggest you to try this:

".*[^:]*: [a-zA-Z0-9]{32}[^:]*: [a-zA-Z0-9]{32}"

First, you don't need to "(..)" or "[...]" one every token. Second, since I don't think you care about "Here is" or "It should be", you can simply look for ":" just before the number you are looking.

I really hope this help.

NawaMan
Works perfectly, thanks! I'm relatively new to regex, so it's a bit confusing.
Rorschach
A: 

Its horrible. You don't need to put everything inside (), only what you need to grab separated in the answer. Read this: http://www.regular-expressions.info/reference.html

/([0-9a-f]{32}).*?should be.*?([0-9a-f]{32})/is

As I'm not a C# programmer I'm just not sure how to pass the /i and /s flags to C# regex (is /s necessary in C#?). I'll edit when I find out.

[Edit]


Regex r;
MatchCollection mc;
r = new Regex("([0-9a-f]{32}).*?should be.*?([0-9a-f]{32})", RegexOptions.Singleline | RegexOptions.IgnoreCase);
mc = r.Matches(VarContainingTheText);
Havenard