Tim Maxey .NET Technology Blog & Resources

November 2010 Entries

RegEx RegEx.Replace Regular Expressions Explained

Ok, gonna try to explain this, for me and for you: I needed to strip apart a strap number like U-22-29-5J5-0000.20 and pass it to the property appraiser's site like: 29225J5000020U Now how do you do that? You have to use Regular Expression Replace, so pattern the above like this: ([0-9a-zA-Z]{1})([\w-]{1})([0-9a-zA-Z]{2})([\w-]{1})([0-9a-zA-Z]{2})([\w-]{1})([0-9a-zA-Z]{3})([\w-]{1})([0-9a-zA-Z]{4})([\w.]{1})([0-9a-zA-Z]{2}) Say what? huh? Let's break it apart. The above regex is the "pattern" to look for, so we are matching in the first () i.e. ([0-9a-zA-Z]{1}) all numbers and letters. Note: each character in the orginal strap is represented by "something" in parentheses () This first set ([0-9a-zA-Z]{1}) is the "U" notice the [...