In article <7p2juvfu8...@mid.individual.net>,
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 ha
On Fri, 18 Dec 2009 17:58:08 -, Alan G Isaac
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, '\' flags an escape w
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 fun
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 repl
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 want
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 repla
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 th
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),
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
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 sublan
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.
B
On Thu, 17 Dec 2009 20:18:12 -, Alan G Isaac
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 right. E.g., \b will b
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 mod
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:
Alan G Isaac 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:
>>> 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 12:19 PM, D'Arcy J.M.
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',
On Thu, 17 Dec 2009 11:51:26 -0500
Alan G Isaac 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 change? Is
tha
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 was
"Alan G Isaac" 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 (i.e., raw strings
En Wed, 16 Dec 2009 11:09:32 -0300, Ed Keith 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 wrote:
Fr
--- 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(.*)
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 wrote:
>>>
Ed Keith
escribió:
> I am having a problem when substituting a raw string.
When I do
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 wrote:
Ed Keith
escribió:
> I am having a problem when substituting a raw string.
When I do the following:
>
> re.sub('abc', r'a\nb\nc', '123abcdefg')
>
>
Ed Keith wrote:
> --- On Wed, 12/16/09, Gabriel Genellina wrote:
>
>> From: Gabriel Genellina
>> 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,
--- On Wed, 12/16/09, Gabriel Genellina wrote:
> From: Gabriel Genellina
> 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
> escribió:
>
> &
On Dec 16, 9:09 am, Ed Keith 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,
>
> -Ed
En Wed, 16 Dec 2009 11:09:32 -0300, Ed Keith 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 http://docs.python.org/library/re.html#re.sub
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
--
h
29 matches
Mail list logo