In article 7p2juvfu8...@mid.individual.net,
Gregory Ewing greg.ew...@canterbury.ac.nz wrote:
MRAB wrote:
In simple cases you might be replacing with the same string every time,
but other cases you might want the replacement to contain substrings
captured by the regex.
But you can give it a
On Fri, 18 Dec 2009 17:58:08 -, Alan G Isaac alan.is...@gmail.com
wrote:
On 12/17/2009 7:59 PM, Rhodri James wrote:
re.compile('a\\nc') passes a sequence of four characters to
re.compile: 'a', '\', 'n' and 'c'. re.compile() then does it's own
interpretation: 'a' passes through as is,
Gregory Ewing greg.ew...@canterbury.ac.nz wrote:
MRAB wrote:
Regular expressions and replacement strings have their own escaping
mechanism, which also uses backslashes.
This seems like a misfeature to me. It makes sense for
a regular expression to give special meanings to backslash
sequences,
Gregory Ewing wrote:
MRAB wrote:
Regular expressions and replacement strings have their own escaping
mechanism, which also uses backslashes.
This seems like a misfeature to me. It makes sense for a regular
expression to give special meanings to backslash sequences, because
it's a sublanguage
On 12/17/2009 7:59 PM, Rhodri James wrote:
re.compile('a\\nc') passes a sequence of four characters to
re.compile: 'a', '\', 'n' and 'c'. re.compile() then does it's own
interpretation: 'a' passes through as is, '\' flags an escape which
combined with 'n' produces the newline character (0x0a),
On 12/18/2009 12:17 PM, MRAB wrote:
In simple cases you might be replacing with the same string every time,
but other cases you might want the replacement to contain substrings
captured by the regex.
Of course that conversion is needed in the replacement.
But e.g. Vim substitutions handle
On 12/19/2009 4:59 AM, Alan G Isaac wrote:
On 12/18/2009 12:17 PM, MRAB wrote:
In simple cases you might be replacing with the same string every time,
but other cases you might want the replacement to contain substrings
captured by the regex.
Of course that conversion is needed in the
MRAB wrote:
In simple cases you might be replacing with the same string every time,
but other cases you might want the replacement to contain substrings
captured by the regex.
But you can give it a function that has access to the
match object and can produce whatever replacement string
it
Gregory Ewing wrote:
MRAB wrote:
In simple cases you might be replacing with the same string every
time, but other cases you might want the replacement to contain
substrings captured by the regex.
But you can give it a function that has access to the match object
and can produce whatever
On Sat, 19 Dec 2009 02:24:00 +, MRAB wrote:
Gregory Ewing wrote:
MRAB wrote:
In simple cases you might be replacing with the same string every
time, but other cases you might want the replacement to contain
substrings captured by the regex.
But you can give it a function that has
En Wed, 16 Dec 2009 11:09:32 -0300, Ed Keith e_...@yahoo.com escribió:
I am having a problem when substituting a raw string. When I do the
following:
re.sub('abc', r'a\nb\nc', '123abcdefg')
I get
123a
b
cdefg
what I want is
r'123a\nb\ncdefg'
On 12/16/2009 9:35 AM, Gabriel Genellina
Alan G Isaac alan.is...@gmail.com wrote in message
news:qemdnrut0jvj1lfwnz2dnuvz_vqdn...@rcn.net...
Naturally enough. So I think the right answer is:
1. this is a documentation bug (i.e., the documentation
fails to specify unexpected behavior for raw strings), or
2. this is a bug
On 12/17/2009 11:24 AM, Richard Brodie wrote:
A raw string is not a distinct type from an ordinary string
in the same way byte strings and Unicode strings are. It
is a merely a notation for constants, like writing integers
in hexadecimal.
(r'\n', u'a', 0x16)
('\\n', u'a', 22)
Yes, that
On Thu, 17 Dec 2009 11:51:26 -0500
Alan G Isaac alan.is...@gmail.com wrote:
re.sub('abc', r'a\nb\n.c\a','123abcdefg') == re.sub('abc',
'a\\nb\\n.c\\a',' 123abcdefg') == re.sub('abc', 'a\nb\n.c\a','123abcdefg')
True
Was this a straight cut and paste or did you make a manual
Alan G Isaac wrote:
On 12/17/2009 11:24 AM, Richard Brodie wrote:
A raw string is not a distinct type from an ordinary string
in the same way byte strings and Unicode strings are. It
is a merely a notation for constants, like writing integers
in hexadecimal.
(r'\n', u'a', 0x16)
('\\n', u'a',
Alan G Isaacalan.is...@gmail.com wrote:
re.sub('abc', r'a\nb\n.c\a','123abcdefg') == re.sub('abc',
'a\\nb\\n.c\\a','123abcdefg') == re.sub('abc', 'a\nb\n.c\a','123abcdefg')
True
Why are the first two strings being treated as if they are the last one?
On 12/17/2009
Alan G Isaac wrote:
Alan G Isaacalan.is...@gmail.com wrote:
re.sub('abc', r'a\nb\n.c\a','123abcdefg') ==
re.sub('abc', 'a\\nb\\n.c\\a','123abcdefg') == re.sub('abc',
'a\nb\n.c\a','123abcdefg')
True
Why are the first two strings being treated as if they are the last one?
On 12/17/2009 2:45 PM, MRAB wrote:
re.compile('a\\nc') _does_ compile to the same as regex as
re.compile('a\nc').
However, regex objects never compare equal to each other, so, strictly
speaking, re.compile('a\nc') != re.compile('a\nc').
However, having said that, the re module contains a cache
Alan G Isaac wrote:
On 12/17/2009 2:45 PM, MRAB wrote:
re.compile('a\\nc') _does_ compile to the same as regex as
re.compile('a\nc').
However, regex objects never compare equal to each other, so, strictly
speaking, re.compile('a\nc') != re.compile('a\nc').
However, having said that, the re
On Thu, 17 Dec 2009 20:18:12 -, Alan G Isaac alan.is...@gmail.com
wrote:
So is the bottom line the following?
A string replacement is not just converted
as described in the documentation, essentially
it is compiled?
That depends entirely on what you mean.
But that cannot quite be
MRAB wrote:
Regular expressions and replacement strings have their own escaping
mechanism, which also uses backslashes.
This seems like a misfeature to me. It makes sense for
a regular expression to give special meanings to backslash
sequences, because it's a sublanguage with its own syntax.
I am having a problem when substituting a raw string. When I do the following:
re.sub('abc', r'a\nb\nc', '123abcdefg')
I get
123a
b
cdefg
what I want is
r'123a\nb\ncdefg'
How do I get what I want?
Thanks,
-EdK
Ed Keith
e_...@yahoo.com
Blog: edkeith.blogspot.com
--
En Wed, 16 Dec 2009 11:09:32 -0300, Ed Keith e_...@yahoo.com escribió:
I am having a problem when substituting a raw string. When I do the
following:
re.sub('abc', r'a\nb\nc', '123abcdefg')
I get
123a
b
cdefg
what I want is
r'123a\nb\ncdefg'
From
On Dec 16, 9:09 am, Ed Keith e_...@yahoo.com wrote:
I am having a problem when substituting a raw string. When I do the following:
re.sub('abc', r'a\nb\nc', '123abcdefg')
I get
123a
b
cdefg
what I want is
r'123a\nb\ncdefg'
How do I get what I want?
Thanks,
-EdK
Ed
--- On Wed, 12/16/09, Gabriel Genellina gagsl-...@yahoo.com.ar wrote:
From: Gabriel Genellina gagsl-...@yahoo.com.ar
Subject: Re: Raw string substitution problem
To: python-list@python.org
Date: Wednesday, December 16, 2009, 9:35 AM
En Wed, 16 Dec 2009 11:09:32 -0300,
Ed Keith e_
Ed Keith wrote:
--- On Wed, 12/16/09, Gabriel Genellina gagsl-...@yahoo.com.ar wrote:
From: Gabriel Genellina gagsl-...@yahoo.com.ar
Subject: Re: Raw string substitution problem
To: python-list@python.org
Date: Wednesday, December 16, 2009, 9:35 AM
En Wed, 16 Dec 2009 11:09:32 -0300,
Ed
En Wed, 16 Dec 2009 14:51:08 -0300, Peter Otten __pete...@web.de
escribió:
Ed Keith wrote:
--- On Wed, 12/16/09, Gabriel Genellina gagsl-...@yahoo.com.ar wrote:
Ed Keith e_...@yahoo.com
escribió:
I am having a problem when substituting a raw string.
When I do the following:
Gabriel Genellina wrote:
En Wed, 16 Dec 2009 14:51:08 -0300, Peter Otten __pete...@web.de
escribió:
Ed Keith wrote:
--- On Wed, 12/16/09, Gabriel Genellina gagsl-...@yahoo.com.ar wrote:
Ed Keith e_...@yahoo.com
escribió:
I am having a problem when substituting a raw string.
When I
--- On Wed, 12/16/09, Peter Otten __pete...@web.de wrote:
Another possibility:
print re.sub('abc', lambda m: r'a\nb\n.c\a',
'123abcdefg')
123a\nb\n.c\adefg
I'm not sure whether that is clever, ugly, or just plain strange!
I think I'll stick with:
m = re.match('^(.*)abc(.*)$',
29 matches
Mail list logo