[issue1761] Bug in re.sub()

2008-01-10 Thread Amaury Forgeot d'Arc
Amaury Forgeot d'Arc added the comment: This may be a surprising behaviour, but consistent with Perl and the pcre library. Added a sentence in documentation, and specific tests. Committed as r59896. -- resolution: -> wont fix status: open -> closed __ T

[issue1761] Bug in re.sub()

2008-01-09 Thread Amaury Forgeot d'Arc
Amaury Forgeot d'Arc added the comment: Aha, I always thought that \Z was an alias for $. __ Tracker <[EMAIL PROTECTED]> __ ___ Python-bugs-list mailing

[issue1761] Bug in re.sub()

2008-01-09 Thread Guido van Rossum
Guido van Rossum added the comment: Which is why I like to use \Z to match *only* the end of the string. __ Tracker <[EMAIL PROTECTED]> __ ___ Python-bug

[issue1761] Bug in re.sub()

2008-01-09 Thread Fredrik Lundh
Fredrik Lundh added the comment: For the record, $ is defined to match "before a newline at the end of the string, or at the end of the string" in normal mode, and "before any newline, or at the end of the string" in multiline mode. (and I have a vague memory that the "before a newline" behaviou

[issue1761] Bug in re.sub()

2008-01-08 Thread Guido van Rossum
Guido van Rossum added the comment: Then I'd say, this is the correct semantics, for better or for worse; add an example to the docs, and a test to the test suite, and close this as wont fix. __ Tracker <[EMAIL PROTECTED]> __

[issue1761] Bug in re.sub()

2008-01-08 Thread Amaury Forgeot d'Arc
Amaury Forgeot d'Arc added the comment: In the previous samples we forgot the /g option needed to match ALL occurrences of the pattern: """ use Data::Dumper; $a = "a\nb\nc"; $a =~ s/$/#/g; print Dumper($a); $a = "a\nb\n"; $a =~ s/$/#/g; print Dumper($a); """ Which now gives the same output as

[issue1761] Bug in re.sub()

2008-01-08 Thread Guido van Rossum
Guido van Rossum added the comment: So if the input ends in '\n', '$' matches both before and after that character, and two substitutions are made (even though multiline is not set). Seems a bug to me. -- nosy: +gvanrossum __ Tracker <[EMAIL PROTECTED]>

[issue1761] Bug in re.sub()

2008-01-08 Thread Georg Brandl
Georg Brandl added the comment: At least, the docs for re.M are consistent with the current behavior. __ Tracker <[EMAIL PROTECTED]> __ ___ Python-bugs-l

[issue1761] Bug in re.sub()

2008-01-08 Thread Amaury Forgeot d'Arc
Amaury Forgeot d'Arc added the comment: Careful, Perl strings must be double-quoted for \n to be understood as the newline character: """ use Data::Dumper; $a = "a\nb\nc"; $a =~ s/$/#/; print Dumper($a); $a = "a\nb\n"; $a =~ s/$/#/; print Dumper($a); """ And the output is: $VAR1 = 'a b c#';

[issue1761] Bug in re.sub()

2008-01-08 Thread Facundo Batista
Facundo Batista added the comment: As re provides regular expression matching operations similar to those found in Perl, I tried there to see what happens: """ use Data::Dumper; $a = 'a\nb\nc'; $a =~ s/$/#/; print Dumper($a); $a = 'a\nb\n'; $a =~ s/$/#/; print Dumper($a); """ $ perl pru_sub.p

[issue1761] Bug in re.sub()

2008-01-08 Thread Fredrik Lundh
Fredrik Lundh added the comment: re.findall has the same behaviour. Without looking at the code, I'm not sure if this is a bug in the code or in the documentation, really. __ Tracker <[EMAIL PROTECTED]> _

[issue1761] Bug in re.sub()

2008-01-08 Thread Georg Brandl
Georg Brandl added the comment: Fredrik? -- assignee: -> effbot nosy: +effbot, georg.brandl __ Tracker <[EMAIL PROTECTED]> __ ___ Python-bugs-l

[issue1761] Bug in re.sub()

2008-01-08 Thread Amaury Forgeot d'Arc
Amaury Forgeot d'Arc added the comment: In other words, if I understand correctly: >>> re.sub('$', '#', 'a\nb\nc') 'a\nb\nc#' >>> re.sub('$', '#', 'a\nb\n') 'a\nb#\n#' The first sample is correct, but the second one find two matches, even without the re.MULTILINE option. Is this normal? The doc

[issue1761] Bug in re.sub()

2008-01-08 Thread Ravon Jean-Michel
New submission from Ravon Jean-Michel: Here is my source: def truc (): line = ' hi \n' line1 = re.sub('$', 'hello', line) line2 = re.sub('$', 'you', line1) print line2 Here is what I get: >>> trace.truc() hi hello helloyou >>> -- components: Regular Expressions message