[thelist] RegExp: new weird problem

Tab Alleman Tab.Alleman at MetroGuide.com
Fri Sep 12 09:49:34 CDT 2003


Tab Alleman wrote:
> Ok, now my pattern looks like this:
> 
> ^PER NIGHT STARTING|ON [0-9]{1,2}\s?[A-Z]{3}[0-9]{0,4} FOR (\d{1,2})
> NIGHTS?$
> 
> Because sometimes I'll get input that looks like this:  "PER NIGHT
> STARTING 05 MAR FOR 4 NIGHTS"
> And sometimes it looks like this:  "PER NIGHT ON 05MAR03 FOR 3 NIGHTS"
> 
> So the change from yesterday is that I've added the "STARTING|ON", and
> the [0-9]{0,4} to catch the possibility that a year will come after
> the month.
> 
> But when I try to match:  "PER NIGHT STARTING 22 MAR FOR 5 NIGHTS",
> The only part that matches is: "PER NIGHT STARTING"
> 
> Why?  Did I not do the "STARTING|ON" correctly?  The pattern matches
> correctly to "PER NIGHT ON 05MAR03 FOR 3 NIGHTS"

Argh, I found that changing my pattern to:

^PER NIGHT (ON|STARTING) [0-9]{1,2}\s?[A-Z]{3}[0-9]{0,4} FOR (\d{1,2})
NIGHTS?$

Fixes the problem, but it means that I have to return "STARTING" or "ON"
as a submatch, and I don't wanna.  Do I hafta, or is there another way?


More information about the thelist mailing list