Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.glorb.com!news-out.readnews.com!transit4.readnews.com!panix!gordon From: John Gordon Newsgroups: comp.lang.python Subject: Re: Find and Replace Simplification Date: Fri, 19 Jul 2013 14:28:41 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 19 Message-ID: References: NNTP-Posting-Host: panix3.panix.com X-Trace: reader2.panix.com 1374244121 27168 166.84.1.3 (19 Jul 2013 14:28:41 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Fri, 19 Jul 2013 14:28:41 +0000 (UTC) User-Agent: nn/6.7.3 Xref: csiph.com comp.lang.python:50907 In Devyn Collier Johnson writes: > I have some code that I want to simplify. I know that a for-loop would > work well, but can I make re.sub perform all of the below tasks at once, > or can I write this in a way that is more efficient than using a for-loop? > DATA = re.sub(',', '', 'DATA') > DATA = re.sub('\'', '', 'DATA') > DATA = re.sub('(', '', 'DATA') > DATA = re.sub(')', '', 'DATA') If your actual use-case is this simple, you might want to use one of the built-in string functions such as strip() or translate(). -- John Gordon A is for Amy, who fell down the stairs gordon@panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies"