Tag | Regular Expressions Posts

Here is a quick notes about using regular expressions in the VS2010 Find Replace dialog. 1. To create a backreference, use curly braces (“{“ and “}” ) instead of regular parentheses. 2. To use the captured backreference, use \1\2 etc, where \1 is the first captured value, \2 is the second captured value, etc. Example: I want to find*: info.setFieldValue(param1, param2); and replace it with: SetFieldValue(info, param1, param2); To do this, I can use the following find/replace values: Find what: {[a-zA-Z0-9]+}.setFieldValu... ...
This post is mostly inspired by a question I came across in the MSDN forums. Basically, say we had a set of data in a string that looked something like this and we just HAAAAAD to use regular expressions to get the info out (I’m insinuating maybe string.split would work better in this situation…) Dim dataToSearch As String = "-Cat-Dog-Meese-Chardonnay-" Well, the pattern is simple right? Just throw in a regex for "-[A-Za-z]+-" and we’re good to go. Dim reg As New Regex("-[A-Za-z]+-") For Each m As ...
In Java, this is not the case as far as I know. However, when working with regular expressions in .NET, be weary of just slapping /d in when you need a number alone. Just like Char.IsDigit isn't just numbers, /d follows suit. The reason is that /d and Char.IsDigit are both validating against the Unicode designation "Nd". This stands for number decimal digit, but does not limit itself to just 0-9. If you're using regular expressions to begin with, you probably already realize that it is fairly easy ...
I was just starting to read the very first pages of the great book "Beautiful Code" (by Andy Oram, Greg Wilson) this morning as a refreshment and as an indirect result to Scott Hanselman's list of basic must-read books (although it didn't include this book - BTW, I read parts of it before, and I don't remember why I stopped), I had to write this post. To all of you guys thinking in DDD, TDD, MVC, ASP.NET, shiny AJAX and RIA (Flash/Silverlight) controls, GC, SharePoint, Rails, Python, ORMs (NHibernate, ...
My favorite Regular Expression resource, RegExLib.com, received a very nice face lift and enhancement recently and I thought you would like to know. For sometime now, the site was sort of broken, search features were not working, paging through the expressions were flaky and it looked like it was on the verge of going away. However, it looks like Steve Smith and the team were making some major enhancements and I am really excited to run into my next RegEx issue and being able to use this resource. ...