[Tutor] Question regular expressions - the non-greedy pattern

2013-01-21 Thread Marcin Mleczko
Hello, in the howto (http://docs.python.org/2/howto/regex.html#regex-howto) there are code examples near the end of the page (the non-greedy pattern) I am referring to: s = 'Title' >>> len(s) 32 >>> print re.match('<.*>', s).span() (0, 32) >>> print re.match('<.*>', s).group() Title print re.ma

Re: [Tutor] Question regular expressions - the non-greedy pattern

2013-01-21 Thread Hugo Arts
On Mon, Jan 21, 2013 at 3:45 PM, Marcin Mleczko wrote: > Now I'm changing the input string to (adding an extra '<'): > > s = ' > and evoking the last command again: > > print re.match('<.*?>', s).group() > I would expect to get the same result > > > > as I'm using the non-greedy pattern.

Re: [Tutor] Question regular expressions - the non-greedy pattern

2013-01-21 Thread Walter Prins
Hi, On 21 January 2013 14:45, Marcin Mleczko wrote: > Did I get the concept of non-greedy wrong or is this really a bug? Hugo's already explained the essence of your problem, but just to add/reiterate: a) match() will match at the beginning of the string (first character) or not at all. As

Re: [Tutor] Question regular expressions - the non-greedy pattern

2013-01-21 Thread Steven D'Aprano
On 22/01/13 01:45, Marcin Mleczko wrote: Now I'm changing the input string to (adding an extra '<'): s = '', s).group() I would expect to get the same result as I'm using the non-greedy pattern. What I get is < Did I get th

Re: [Tutor] Question regular expressions - the non-greedy pattern

2013-01-21 Thread Marcin Mleczko
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hello Hugo, hello Walter, first thank you very much for the quick reply. The functions used here i.e. re.match() are taken directly form the example in the mentioned HowTo. I'd rather use re.findall() but I think the general interpretetion of the giv

Re: [Tutor] Question regular expressions - the non-greedy pattern

2013-01-21 Thread Steven D'Aprano
On 22/01/13 10:11, Marcin Mleczko wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hello Hugo, hello Walter, first thank you very much for the quick reply. The functions used here i.e. re.match() are taken directly form the example in the mentioned HowTo. I'd rather use re.findall() but I

Re: [Tutor] Question regular expressions - the non-greedy pattern

2013-01-21 Thread Walter Prins
Hi Marcin, On 21 January 2013 23:11, Marcin Mleczko wrote: > first thank you very much for the quick reply. > No problem... > The functions used here i.e. re.match() are taken directly form the > example in the mentioned HowTo. I'd rather use re.findall() but I > think the general interpretet

Re: [Tutor] Question regular expressions - the non-greedy pattern

2013-01-21 Thread Lie Ryan
On 22/01/13 10:11, Marcin Mleczko wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hello Hugo, hello Walter, first thank you very much for the quick reply. The functions used here i.e. re.match() are taken directly form the example in the mentioned HowTo. I'd rather use re.findall() but I

Re: [Tutor] Question regular expressions - the non-greedy pattern

2013-01-21 Thread Alan Gauld
Your understanding is flawed. Try these actions and ponder their significance... >>> s = '>> re.search('<.*?>',s).group() '<' >>> re.search('<.*>',s).group() '>> s = '>> re.search('<.*>',s).group() '<' >>> re.search('<.*t',s).group() '>> re.search('<