Attention: We are retiring the ASP.NET Community Blogs. Learn more >

ShowUsYour<Blog>

Irregular expressions regularly

  • RegexLib.com - Rss + Notifications!

    For the 2nd time this week I've used the code in the recent Rss article on Msdn to write an Rss feed, this time it was to make available a feed of the latest Regex patterns that are added to the RegexLib.com site.  I've added the little orange "Xml" link on the side menu and you can add the feed to your aggregator by pointing it to the following link:

  • RegexLib.com features added

    I spent some time this weekend altering RegexLib.com to try and push more information to the "front" of the site.  I've added a couple of repeaters to the Home page that show a listing of recent patterns and also the top 10 contributors.  Clicking on a top contributor takes you to a page that shows all patterns submitted by that particular user.  This is a new page and I'm hoping that it will make the site even more popular and further entice people to use RegexLib.com to store their own patterns.

  • A new look and feel

    As I mentioned last week, I've changed the look and feel I've my blog ( thanks to ScottW! ).

  • Broadsheeted Blogging

    I stumbled across this site today which points to the future direction of the blogging “industry“:

  • Regex to capture an attribute collection

    Wayne posted an elegant solution on the regex list today in answer to the following question: "How do I find all INPUT tags and pick out the attribute/values within them?". For the record, here's the pattern that Wayne came up with

    <input \s+
      (
        (?'Attr'\w+) \s* = \s*
        (?'Value' [^\s"'>]+ | "[^"]*" | '[^']*')
        \s*
      )*      #match zero or more Attrs
      /?>
    
    ... and here is some sample code that he provided for demonstrating its use (NOTE: the usage of the Captures on each Match'ed item):
      Regex rex = new Regex(@"
          <input \s+
          (
            (?'Attr'\w+) \s* = \s*
            (?'Value' [^\s""'>]+ | ""[^""]*"" | '[^']*')
            \s*
          )*      #match zero or more Attrs
          /?>",
          RegexOptions.ExplicitCapture |
          RegexOptions.IgnorePatternWhitespace);
      
      foreach(Match m in rex.Matches( textToSearch ))
      {
        Console.WriteLine("Found a match with these attributes:");
        for(int i=0; i < m.Groups["Attr"].Captures.Count; i++) {
          Console.WriteLine("Attr:  " + m.Groups["Attr"].Captures[i].Value);
          Console.WriteLine("Value: " + m.Groups["Value"].Captures[i].Value);
        }
        Console.WriteLine();
      }
     
    If you're not on the regex list already and you are even remotely interested in them, then I behoove you to jump over and sign-up today. It's a low-traffic, highly focussed list and it's full of smart people like Wayne :-)

  • Is structure good?

    I've asked many programmers/developers about where they want to end up and, often the reply is: "Me?  I'm going to work for Microsoft.  Gunna cut some elite code working on the kernel!".  Which I always interpret to mean: "Me?  Well apparently Bill's got a shitload of money and he's giving everyone free Jolt cola... that's where I'm heading!".