3 ms·
Yes, I'm comparing it to languages which have regex operators (Perl, Ruby) and where you don't have to `import re`.
by cutler 6y ago
Yes, I'm comparing it to languages which have regex operators (Perl, Ruby) and where you don't have to `import re`.
- acdha 6y agoOkay, so that's a somewhat different claim and it really comes down to how much you care about an operator versus a extra couple of characters. Most programmers know how to touch-type and do not hammer out regexps so quickly that the difference between: $foo =~ s/foo/bar/ and foo = re.sub("foo", "bar", foo) is a significant factor in deciding which language to use, especially since there are legibility tradeoffs (i.e. escaping) and the Python approach for handling e.g. groups is cleaner for non-trivial code and avoids the chance of accidentally clobbering $1, $2, etc. — a bug pattern I've seen affect people more than once. Personally, if I were advocating Perl I'd probably go with angles like the extended capabilities or more complete Unicode support which Python users need to get from the regex module (https://pypi.org/project/regex/ https://pypi.org/project/regex/).
- Daishiman 6y agoHaving been raised into the profession at a time when both Perl and Python were strong, the amount of times I have had to reach for regexes as a frequent solution to a problem is so rare that I can hardly see how it's a problem. It's about as much of a problem as not having built-in linear algebra operators.
- fatbird 6y agoI thought this as well but didn't want to get sidetracked on a specific. Perl was one of my first languages and regexes were one of the big tools I started using, while I was processing text files. Once parsing lines of ASCII stopped being my major task, regexes stopped being a frequent tool.