2012-07-26 62 views
2

我正在尝试从IMDb中获取人体高度,但该行包含#,它表示PHP中的注释(例如# The comment as follows)。这里是如何看起来像来自IMDB的源代码:从IMDb获取人体高度

<h4 class="inline">Height:</h4> 
5' 7&#34; (1.70 m) 

这是我尝试的正则表达式:

<h4 class="inline">Height:</h4>\n([0-9' &#;(.)m]+)

我应该怎么做,以防止它后发表评论正则表达式的其余部分#角色?

在此先感谢!

编辑

这里是添加\正则表达式的结果: enter image description here

+1

[取来自这里的建议。](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags) – 2012-07-26 23:08:30

+3

请勿使用RegEx。 http://simplehtmldom.sourceforge.net/或http://php.net/manual/en/book.dom.php – 2012-07-26 23:08:59

+1

用\ \转义它吧? – Radix 2012-07-26 23:09:45

回答

2

我已经解决了我的问题,下面是答案:

/<h4 class="inline">Height:<\/h4>\n([0-9\' ]+)&#34; ([0-9. m()]+)/

+1

drats!打了我一分钟 - 把它放在船上。恭喜加1自给自足! – Radix 2012-07-26 23:27:47

+0

呵呵。非常感谢 :) – Erik 2012-07-27 00:13:50