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

Reflecting on my Regular Expression talk

Last night I have a talk on Regular Expressions for PAFOX a Visual FoxPro usergroup.  Apparently there was a three part article in FoxTalk2.0 by Lauren Clarke and Randy Pearson about text manipulation that described an implementation/fusion of Regular Expressions with native VFP string/test functions.  Tim Yeaney wanted to fill in some blanks for the group so he got in touch with Geoff Snowman, our Developer Champion, who put him in touch with me.

The slide deck for the presentation is over on the Thycotic site but I'll warn you, there's not a whole lot of meat.  That's not to say it was a quick talk, it went for an hour and a half.  The problem with discussing regular expressions (regex) is that you have to strike a balance.  No one in my audience came from a pure computer science background, had any experience in language construction, compiler design, lexers and though I didn't ask any *nix tools like sed, awk, grep or PERL (no, it's not just a *nix tool, I know).  So the theory / background leaned a lot more towards "it's a pattern describing a set of strings" instead of the formal language theory.

We quickly set aside theory and went into practical usage, starting with some typical contrived examples you might see in data validation.  I was using The Regulator during the presentation, a choice I regret and I'll explain why in a moment, to demonstrate matching.  Another thing you won't find in my slide deck is a list of characters and symbols [], [^], \d, \W, etc.  Not because I don't think that's useful, because I wanted to focus on the intent of regex and not necessarily the details.  Sure I'm discussins a specific implementation (System.Text.RegularExpressions) for use with VFP but I'm also talking about a tool that has many different implementations (look at VS.NET search and replace with regex for example, or for that matter just about any text editor has their own version of regex).  It's important to understand the concepts, you can get the details from a reference.

I showed a few examples where it could be used in search, how string replacement worked and we ended by working through log parsing.  The log parsing example was interesting because it tied a lot of pieces together.  If you ever try something like this, make your log short 10, 15, 20 lines is probably plenty, I started with a 24K file and quickly pared it down.

One last note about my slide deck, I'm probably the first guy to talk about regex in .NET and not mention regexlib.  That's not an oversight.  I think regex is a fairly useful tool but like every tool there are appropriate times to use it and not use it.  I've discussed this before over on my regex blog before.  Yes it is possible to define a single regex to do a lot of the things I don't agree with, doesn't mean they're wrong, but I'm not going to encourage those things.

Regrets, thoughts, etc:

  • Using The Regulator.  I'm not busting on Roy or his tool.  I think it is a great tool but it doesn't have a place--at least for me--during a presentation for several reasons:
    • I can't change font size, if you can, let me know how, I couldn't find it.
    • I want to turn off "intellisense", it just gets in my way.  This was especially true when not building the complete expression from left to right.  I liked to go back and refactor the expression, then I'd be caught in the intellisense bit and have to remember to escape out of it before trying to move the cursor somewhere.
    • I want to turn off scope matching brackets, parens, braces for pretty much the same reason as intellisense.  I think they're a great idea for a beginner but I'd really like to turn that off.
  • Maybe install PowerGrep or something so the search demonstration could be a little more flexible.
  • Not having made a minimal quick reference dealing just with basic ECMA, no lookaround stuff and no code just something I could pop back and forth to when I'm describing a new pattern.

There weren't a whole lot of questions.  I'm not sure this was good or bad.  I think neither, just that like any other tool unless when you learn about it you have a specific need where it coud be applied to make your life better you don't know what questions to ask yet.  I could have spent some time quizing the audience, this would probably work a lot better if there was a whiteboard around (or they just pass the keyboard around or something -- not wireless, so I'll have to remember that if I want to try it).

Sponsor
Published Friday, January 07, 2005 9:17 AM by jeffrey

Comments

 

jeffrey said:

As far as the Regulator goes, I don't know what version you are using but I am using version 2.0.3 and you can access the font dialouge via the context menu, under options , of the main window. Oddly enough the context menu has more options available than the main menubar. Although this only seem to apply to the pattern window and not the input, match and replace windows. It would be nice if you adjust the fonts of those windows too.

Intellisense does get in the way but can be turned off via the options under view of the menubar.
Though I don't know if you can turn off the scope matching you can change the font color to be the same as your background so you wouldn't be able to see them.
January 7, 2005 1:28 PM
 

jeffrey said:

It's Perl (the language) or "perl" (the binary compiler), but never PERL.
March 9, 2005 12:07 AM
 

Reflecting on my Regular Expression talk said:

November 26, 2007 6:26 PM
 

http://regexadvice.com/blogs/jschoolcraft/archive/2005/01/07/264.aspx said:

March 23, 2008 3:25 AM
Anonymous comments are disabled