[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 __

[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 behaviour in

[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] http://bugs.python.org/issue1761 __ ___

[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] http://bugs.python.org/issue1761 __ ___ Python-bugs-list mailing

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

[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 docs

[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.pl

[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] http://bugs.python.org/issue1761 __ ___ Python-bugs-list

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