On 30-6-2012 15:23, Sunny Nanda wrote:
> You can try the following two suggestions:
>
> 1. Try removing the "^" from the pattern and match only r"<img". I believe
> that the image tag might not be coming at the start of the string.
That, and re.match is bound to the start of the string. See:
http://docs.python.org/release/2.7.2/library/re.html#search-vs-match
What you're looking for is:
prog = re.compile(r'<img.*?/>')
matches = re.search(prog)
for match in matches :
print match
> On a sidenote, you should not be using regular expressions if you are doing
> anything complex that what you are doing right now.
This isn't complex. The email validator in django is complex. Using an
XML parser for this is quite overkill. If you need several elements
based on their nesting and/or sister elements, then an XML parser makes
more sense, or better xpath queries. This is simple stuff for regular
expressions and what they're made for.
--
Melvyn Sopacua
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment