Re: best way to do a series of regexp checks with groups

2005-01-24 Thread Mark Fanty
This is the kind of thing I meant. I think I have to get used to writing small, light-weight classes. You inspired this variation which is a little more verbose in the class definition, but less so in the use: class Matcher: def search(self, r,s): self.value = re.search(r,s) return

best way to do a series of regexp checks with groups

2005-01-23 Thread Mark Fanty
In perl, I might do (made up example just to illustrate the point): if(/add (\d+) (\d+)/) { do_add($1, $2); } elsif (/mult (\d+) (\d+)/) { do_mult($1,$2); } elsif(/help (\w+)/) { show_help($1); } or even do_add($1,$2) if /add (\d+) (\d+)/; do_mult($1,$2) if /mult (\d+) (\d+)/; show_help($1