On Mon, Sep 28, 2015 at 8:43 PM, Steven D'Aprano
(3) Using a regular expression is probably the "right" answer, at least from a comp sci theorectical perspective. This is precisely the sort of thing that regexes are designed for. Unfortunately, regex syntax is itself a programming language[1], and a particularly cryptic and unforgiving one, so even quite experienced coders can have trouble.
indeed -- we all know the old maxim: "I had a problem, and thought "I know, I'll use regular expressions" -- now I have two problems. And the Python "obvious way to do it" has always been for simple string manipulation, see if what you need is in a string method before you bring out the big guns of REs After all, if "use REs" was the answer to simple string manipulation problems, the string object would have a lot fewer methods. So: I've frequently had this use-case, too -- it would be a nice enhancement that would had substantial utility to strings. Whether it used an re under the hood or not should be an implementation detail. -CHB -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker@noaa.gov