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
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://
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
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
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
<[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
> 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
> 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
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