Because the regular expression <H*> means “match an angle-bracket character, 
zero or more H characters, followed by a close angle-bracket character” and 
your string does not match that pattern.

This is why it’s best to check that the match succeeded before going ahead to 
call group() on the result (since in this case there is no result).


On 18-Feb-2014, at 09:52, Santosh Kumar <rhce....@gmail.com> wrote:

> 
> Hi All,
> 
> If you notice the below example, case I is working as expected.
> 
> Case I:
> In [41]: string = "<H*>test<H*>"
> 
> In [42]: re.match('<H\*>',string).group()
> Out[42]: '<H*>'
> 
> But why is the raw string 'r' not working as expected ?
> 
> Case II:
> 
> In [43]: re.match(r'<H*>',string).group()
> ---------------------------------------------------------------------------
> AttributeError                            Traceback (most recent call last)
> <ipython-input-43-d66b47f01f1c> in <module>()
> ----> 1 re.match(r'<H*>',string).group()
> 
> AttributeError: 'NoneType' object has no attribute 'group'
> 
> In [44]: re.match(r'<H*>',string)
> 
> 
> 
> Thanks,
> santosh
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to