Re: any chance regular expressions are cached?

2008-03-10 Thread Arnaud Delobelle
On Mar 10, 3:39 am, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: [...] > Having said that, at least four out of the five examples you give are > good examples of when you SHOULDN'T use regexes. > > re.sub(r'\n','\n'+spaces,s) > > is better written as s.replace('\n', '\n'+spaces). D

Re: any chance regular expressions are cached?

2008-03-10 Thread John Machin
On Mar 10, 3:42 pm, John Machin <[EMAIL PROTECTED]> wrote rather baroquely: > ...>>> def myfunc(s, spaces): > > ... return '\n'.join(spaces + x.rstrip() if x.rstrip() else '' for > x in s.splitlines()) Better: ... return '\n'.join((spaces + x).rstrip() for x in s.splitlines()) -- http://

Re: any chance regular expressions are cached?

2008-03-10 Thread mh
John Machin <[EMAIL PROTECTED]> wrote: > Yes they will be cached. great. > But do yourself a favour and check out the > string methods. Nifty... thanks all! -- Mark Harrison Pixar Animation Studios -- http://mail.python.org/mailman/listinfo/python-list

Re: any chance regular expressions are cached?

2008-03-09 Thread John Machin
On Mar 10, 11:42 am, [EMAIL PROTECTED] wrote: > I've got a bit of code in a function like this: > > s=re.sub(r'\n','\n'+spaces,s) > s=re.sub(r'^',spaces,s) > s=re.sub(r' *\n','\n',s) > s=re.sub(r' *$','',s) > s=re.sub(r'\n*$','',s) > > Is there any chance that these will be cach

Re: any chance regular expressions are cached?

2008-03-09 Thread Steven D'Aprano
On Mon, 10 Mar 2008 00:42:47 +, mh wrote: > I've got a bit of code in a function like this: > > s=re.sub(r'\n','\n'+spaces,s) > s=re.sub(r'^',spaces,s) > s=re.sub(r' *\n','\n',s) > s=re.sub(r' *$','',s) > s=re.sub(r'\n*$','',s) > > Is there any chance that these will be c

Re: any chance regular expressions are cached?

2008-03-09 Thread Terry Reedy
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | I've got a bit of code in a function like this: | |s=re.sub(r'\n','\n'+spaces,s) |s=re.sub(r'^',spaces,s) |s=re.sub(r' *\n','\n',s) |s=re.sub(r' *$','',s) |s=re.sub(r'\n*$','',s) | | Is there any chance that these w

RE: any chance regular expressions are cached?

2008-03-09 Thread Ryan Ginstrom
> On Behalf Of Tim Chase > Sounds like what you want is to use the compile() call to > compile once, and then use the resulting objects: > >re1 = re.compile(r'\n') >re2 = re.compile(r'^') >... >s = re1.sub('\n' + spaces, s) >s = re2.sub(spaces, s) Yes. And I would go a step f

Re: any chance regular expressions are cached?

2008-03-09 Thread Tim Chase
> s=re.sub(r'\n','\n'+spaces,s) > s=re.sub(r'^',spaces,s) > s=re.sub(r' *\n','\n',s) > s=re.sub(r' *$','',s) > s=re.sub(r'\n*$','',s) > > Is there any chance that these will be cached somewhere, and save > me the trouble of having to declare some global re's if I don't > want t

any chance regular expressions are cached?

2008-03-09 Thread mh
I've got a bit of code in a function like this: s=re.sub(r'\n','\n'+spaces,s) s=re.sub(r'^',spaces,s) s=re.sub(r' *\n','\n',s) s=re.sub(r' *$','',s) s=re.sub(r'\n*$','',s) Is there any chance that these will be cached somewhere, and save me the trouble of having to declare som