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

Michael Ash's Regex Blog

Regex Musings

Know Your Syntax(es)

It's always good to know what syntax your regex engine, for the language you are working with, does and does not support.  Some language support more, some less.  I've seen a lot of comments on the regexlib about regexes that don't work in javascript and most of the time it's a syntax issue. 

I got bit by that bug today.  Working in VB 6 I was using some regexes to parse some filepaths pulling back certain sub-folders.  They worked mostly but they weren't catching the folder that had non-alphanumeric characters.   Which isn't surprising since I was only testing for alphanumerics.  So i went over to the regexlib and found just what I needed and paste it in the appropriate place.  But as I was stepping through my code suddenly the Regexp object wasn't working.   I was first looking to see if there was a match and if there was executing the regex pull what I needing out of the match collection.  As I stepped thru the if test would branch as though it was returning true, bu the execute wouldn't return any matches.   I copied the expression and pasted into the regulator.  Tested it with the input that wasn't working and it worked like It should have.  But when I again test my code the regexp still weren't working right. And the error message were generic and unhelpful. I was completely baffled  I was going nuts trying to figure out what was wrong.  I rebooted,  reinstalled the scripting engine, didn't help.  Then it dawned on me.  The snippet I copied from the regexlib was using a look-behind and the VBScript regex syntax doesn't support look-behinds.   So basically there was a syntax error (for VBScript) in the pattern.  So none of the Regexp's methods were working with the invalid pattern  throwing up none descriptive error message.I changed the regex back to it's original form and everything started working again. 

Today's lesson?  test your regexes with the same engine you are going to use it with.

Sponsor
Published Tuesday, July 13, 2004 6:30 PM by mash

Comments

 

TrackBack said:

August 5, 2004 5:55 PM
 

TrackBack said:

October 5, 2004 4:58 PM
 

TrackBack said:

October 5, 2004 4:59 PM
 

TrackBack said:

November 8, 2004 8:27 PM
 

rimonabantexcellence site title said:

June 4, 2013 3:21 PM
Anonymous comments are disabled