Thursday, September 30, 2010

RegEx in Dot Net

While attempting to parse a QuickBooks export file, I had need to match a rather complicate pattern.  The pattern was easy do express in Regular Expressions, but not so much with normal string handling in Dot Net.

Proving that everything and the kitchen sink is available in the Dot Net Framework, here is how you can use the beauty of Regular Expressions in Visual Basic 2008.

Imports    System.Text.RegularExpressions.
sub amatch
 dim aMatch = Regex.Match(InputField, ":[0-9A-Za-z]* " & Chr(&HB7))
if aMatch.Success then
   'Do Something
end if