regular expression for parsing an html element

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • abcd

    #1

    regular expression for parsing an html element

    I have some HTML such as....

    <a href="...."><im g src="image/blah/a.jpg" id="ddddd">bla h blah blah</
    a>....

    I wnat to pull out the text that lies inside the quotes of the src
    attribute. So in this example I would get image/blah/a.jpg

    My regex so far is: src=\"(.*)\" ....however the group in this case
    would end up being, image/blah/a.jpg" id="ddddd">bla h blah blah</
    a>.....

    how can I tell the regex group (.*) to end when it gets to the first
    " ?

    thanks

  • =?ISO-8859-2?Q?Wojciech_Mu=B3a?=

    #2
    Re: regular expression for parsing an html element

    abcd wrote:
    My regex so far is: src=\"(.*)\" ....however the group in this case
    would end up being, image/blah/a.jpg" id="ddddd">bla h blah blah</
    a>.....
    >
    how can I tell the regex group (.*) to end when it gets to the first
    " ?
    Use non-greedy matching, i.e. src=\"(.*?)\" (question mark after *.)
    See: http://docs.python.org/lib/re-syntax.html

    w.

    Comment

    • abcd

      #3
      Re: regular expression for parsing an html element

      thanks, forgot that.

      Comment

      Working...