Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Using Regex to parse WSUS update list for KB Articles.

Posted on 2011-03-20
2
Medium Priority
?
656 Views
Last Modified: 2013-12-17


This is what I am trying to filter.
        Security Update for Windows 7 for x64-based Systems (KB2479943)
        Windows Malicious Software Removal Tool x64 - March 2011 (KB890830)
        Update for Microsoft Silverlight (KB2495644)
        Security Update for Windows 7 for x64-based Systems (KB2483614)
        Cumulative Security Update for Internet Explorer 8 for Windows 7 for x64-based S
        ystems (KB2482017)
        Security Update for Windows 7 for x64-based Systems (KB2425227)
        Windows Malicious Software Removal Tool x64 - February 2011 (KB890830)
        Security Update for Windows 7 for x64-based Systems (KB2479628)
        Update for Windows 7 for x64-based Systems (KB2467023)
        Windows Live Essentials 2011 (KB2434419)
        Update for Windows 7 for x64-based Systems (KB2454826)
        Security Update for Windows 7 for x64-based Systems (KB2475792)
        Security Update for Windows 7 for x64-based Systems (KB2393802)
        Security Update for Windows 7 for x64-based Systems (KB2485376)
        Update for Windows 7 for x64-based Systems (KB976902)
        Windows Malicious Software Removal Tool x64 - January 2011 (KB890830)
        Security Update for Windows 7 for x64-based Systems (KB2419640)
        Update for Internet Explorer 8 Compatibility View List for Windows 7 for x64-bas
        ed Systems (KB2447568)
        Cumulative Update for Media Center for Windows 7 x64-based Systems (KB2284742)
        Update for Microsoft Silverlight (KB2477244)

Open in new window


and I am trying to filter for  the KB Article: (KB2477244)

The pattern I ended up working with looked like this:
(((\w{2}\d{7}) ?))

Open in new window

I am sure that there are other ways to tackle this like (((KB\d{7}) ?))

Quickly wrote this method to test this (Cover your eyes!)

 <Omitted for brevity>    
//Display WSUS results from Custom COM+ interop class     
List<string> KbUpdates = new List<string>();
Console.WriteLine("=====================================================================================");
foreach (string s in KbUpdates)
{
    string format = string.Format("Title:{0}\r\nKB#:{1}", s, GrabKBUpdate(s.ToString()));
                
    Console.WriteLine(format);
                Console.WriteLine("=====================================================================================");
 }

public string GrabKBUpdate(string updatestring)
        {
            string result = string.Empty;
            string pattern = @"(((\w{2}\d{7}) ?))", input = updatestring;
            Regex rgx = new Regex(pattern, RegexOptions.Multiline);// IgnoreCase
            MatchCollection matches = rgx.Matches(input);

            if (matches.Count > 0)
            {
                // Just wanted the first result as that is the only one that should be in the line.
                foreach (Match match in matches)
                   result = match.Value;
                return result;
                //Console.WriteLine("(Matches {0} {1}):", input, matches.Count);
                //foreach (Match match in matches)
                //    Console.WriteLine("   " + match.Value);
            }
            return result;
        }

Open in new window


Results look like this:
=====================================================================================
Title:Security Update for Windows 7 for x64-based Systems (KB2479943)
KB#:KB2479943
=====================================================================================
Title:Windows Malicious Software Removal Tool x64 - March 2011 (KB890830)
KB#:
=====================================================================================
Title:Update for Microsoft Silverlight (KB2495644)
KB#:KB2495644
=====================================================================================
Title:Security Update for Windows 7 for x64-based Systems (KB2483614)
KB#:KB2483614
=====================================================================================
Title:Cumulative Security Update for Internet Explorer 8 for Windows 7 for x64-based Systems (KB2482017)
KB#:KB2482017
=====================================================================================

Open in new window



Problems:
If you take a look at the results only the articles with 7 digits get extracted and nothing less than or greater than 7 gets extracted.
Using pattern "(((\w{2}\d{6}) ?))" returns partial results that look like this.
=====================================================================================
Title:Security Update for Windows 7 for x64-based Systems (KB2479943)
KB#:KB247994
=====================================================================================

Questions:

1. Is there a better regex pattern to filter for these or better yet a pattern plus a smoother running method? Explanations/Comments/Suggestions are welcome as well.


Conclusion:
This method will be used in a security analysis tool.
0
Comment
Question by:Russell_Venable
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 12

Accepted Solution

by:
enachemc earned 1000 total points
ID: 35178473
(KB\d+)
0
 
LVL 15

Author Closing Comment

by:Russell_Venable
ID: 35184903
Seriously? lol. That is so easy! Thanks! I totally overlooked adding a +. Good pointing that out!
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question