4 ms·
If you want to match a regexp in Python, you can just say: m = re.match("some_regexp", my_str) You don't need to compile regexps before use but you get better
by jergosh 15y ago
If you want to match a regexp in Python, you can just say:
m = re.match("some_regexp", my_str)
You don't need to compile regexps before use but you get better performance if you do when matching the same thing multiple times (no idea if there's a Perl equivalent). Also match() and search() have different semantics and you don't use them at the same time. So it's one statement in Python per match.
Also how do you propose to get an equivalent of (non-mandatory) exception handling in Perl code without extra statements?
- ajross 15y agoPerl's regexes are part of the syntax of the language. They're compiled when the script is. That's why the perl syntax is cleaner and the implementation more robust. A bug table of regexes to parse fields out of a record or whatnot looks natural (i.e. declarative) in perl; in python it's kind of a big, imperative mess. Perl exception handling is quirky, but pretty clean. You raise an exception with die() and "try" a block with a simple eval. It's basically the same amount of syntax. The one bit perl lacks as a builtin is the type-based exception matching; you have to do that logic yourself.