EXI-Andrews, Jack wrote:
the '*' and '+' don't seem to be greedy.. they will consume less in
order to match a string:
import re;re.match('(a+)(ab)','aaab').groups()
('aa', 'ab')
this is the sort of behaviour i'd expect from
'(a+?)(ab)'
a+ should greedily consume a's at the expense
I wrote:
import re;re.match('(a+)(ab)','aaab').groups()
('aa', 'ab')
this is the sort of behaviour i'd expect from
'(a+?)(ab)'
a+ should greedily consume a's at the expense of the string
not matching
Fredrick wrote:
that's a misunderstanding of what a regular expression is,
EXI-Andrews, Jack wrote:
that's a misunderstanding of what a regular expression is, though:
conceptually, a RE describes a set of strings, and the RE engine is
designed to answer the question does this string belong to this
set.
if that's so, what is the point of +? and *? (?)
the '*' and '+' don't seem to be greedy.. they will consume less in
order to match a string:
import re;re.match('(a+)(ab)','aaab').groups()
('aa', 'ab')
this is the sort of behaviour i'd expect from
'(a+?)(ab)'
a+ should greedily consume a's at the expense of the string not matching
in
EXI-Andrews, Jack wrote:
the '*' and '+' don't seem to be greedy.. they will consume less in
order to match a string:
import re;re.match('(a+)(ab)','aaab').groups()
('aa', 'ab')
this is the sort of behaviour i'd expect from
'(a+?)(ab)'
a+ should greedily consume a's at the expense of
* Carl Banks wrote:
I'm suddenly curious if there are any cases at all where
greediness changes whether it finds a match.
nope, per definitionem ;-)
greedy := longest leftmost match
nd
--
die (eval q-qq[Just Another Perl Hacker
]
;-)
# André Malo, http://www.perlig.de/ #
--
Carl Banks wrote:
EXI-Andrews, Jack wrote:
the '*' and '+' don't seem to be greedy.. they will consume less in
order to match a string:
import re;re.match('(a+)(ab)','aaab').groups()
('aa', 'ab')
this is the sort of behaviour i'd expect from
'(a+?)(ab)'
a+ should greedily consume a's