0

i want to get div tag's content. For example:

<div id="gameDetailsInner">
<div id="headerText" style="padding-left: 0px !important;padding-top: 0px !important;">
<h1><a href="http://www.abc.com/games.php?flash=7264">abc text</a></h1>
</div>
<div style="min-height: 90px;">
<a href="http://www.abc.com/games.php?param=12345"><img src="http://abc.abc.com/images/7264.jpg" alt="abc" width="120" height="78" id="gameDetailsInnerImg"/>
</a>
How can i get this text with regex?
</div>

Thanks...

Trufa
  • 39,971
  • 43
  • 126
  • 190
Özkan Selek
  • 21
  • 1
  • 4

3 Answers3

1

If you're in PHP, you can use the strip_tags() function to remove all HTML tags from a string.

Anything more than that, you need to use a proper HTML parser. You can't parse HTML with regular expressions. You need to use a proper HTML parser. http://htmlparsing.com lists a number of solutions for different languages.

Andy Lester
  • 91,102
  • 13
  • 100
  • 152
1

Unfortunately, you can't reliably parse HTML using a Regex. Please see this famous question for details: RegEx match open tags except XHTML self-contained tags

Community
  • 1
  • 1
Scott Chapman
  • 920
  • 1
  • 7
  • 13
0
<div.*>([^>]+)</div>

Group1 gives the content of the div if the content is just before the end </div>

prageeth
  • 7,159
  • 7
  • 44
  • 72