Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Regex According to Jeff

The right tool for the right job

Daily Dose of Regex

In a previous post I complained about the regex replace capabilities inside VS.NET 2003.  That’s not to say I don’t use them, I’m certainly going to use PowerGREP for any multiple file replacements, I do especially with NUnitAsp.

Typical to us, starting some GUI testing, we’ll define a bunch of Testers and then “new them up” so we can get on with writing our tests.  One handy trick we use is copying our definition list and then regex replace the copy into the “new” version.

The whole process looks something like this:

Regex

I’m about midway through my replacement at this point but it’s a whole lot easier to do this (easier == less keystrokes) than it is to rekey or try to manually cut around some of those breaks to do the work yourself.

This does get to some of my annoyances of VS.NET 2k3’s implementation of Regular Expressions.  I have to use an expression like this:

protected:b+{[^:b]+}:b+{[^:b]+}:b+=:b+null;

Instead of something like (called out visually different to make a point, black bordered code is what you would use in the Find/Replace with regex dialog in VS.NET):

protected\s+([^\s]+)\s+([^\s]+)\s+=\s+null;

Major differences are groups are called out with { } instead of ( ) and all my shortcuts (like \s for whitespace) are different (:b being the equivalent for whitespace, well :Wh is there as well, thank god!).  For those that are interested the replacement looks like this:

\2 = new \1("\2", CurrentWebForm);

Not that Regular Expressions are a giant mystery, and I’m happier to have people learn the concepts than syntax, it is nice to be able to learn one syntax and use it than being bothered with mapping one implementation to another.

Sponsor
Published Monday, March 07, 2005 3:53 PM by jeffrey
Filed under:

Comments

No Comments
Anonymous comments are disabled