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
__
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
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
__
___
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
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:
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
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
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
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]
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:
10 matches
Mail list logo