0

normally, in html, youtube can be presented as

<object width="420" height="315"><param name="movie" value="http://www.youtube.com/v/qvt_Ae1eRPo?version=3&amp;hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/qvt_Ae1eRPo?version=3&amp;hl=en_US" type="application/x-shockwave-flash" width="420" height="315" allowscriptaccess="always" allowfullscreen="true"></embed></object>

My question is that what's the regex that can retrieve this "object" block from a HTML string?

Thanks

Jackson Tale
  • 25,428
  • 34
  • 149
  • 271
  • 1
    [You shouldn't try to parse HTML with regex](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454) – Bohemian Oct 27 '11 at 23:40
  • Please choose the appropriate library/utility depending on your framewrok and refrain yourself from using regexes for tasks such as this. – FailedDev Oct 27 '11 at 23:46
  • @Bohemian, what if I am sure this tags are valid one, and only need this part in the whole HTML? – Jackson Tale Oct 28 '11 at 10:23
  • If you're *sure*, then it's OK. The risk is that some "web guy" changes the HTML is some weird way and your code breaks, even though the site does not. – Bohemian Oct 28 '11 at 19:52

1 Answers1

1

/<object.+?<\/object>/mis should work, please note that if you want a proper retrieval of HTML tags and their contents, you should really use a parser

Ben
  • 13,297
  • 4
  • 47
  • 68
  • thanks, but why? if I only need to retrieve , does it matter? – Jackson Tale Oct 27 '11 at 23:52
  • if you are just looking for this particular tag, there is not object element nested inside another object and it always has the format of AND you are only interested in retrieving the entire element, you should be ok. – Ben Oct 27 '11 at 23:56