[Israel.pm] extract ip from html

Oded Arbel oded-linux at typo.co.il
Mon Aug 6 09:36:58 PDT 2007

On Mon, 2007-08-06 at 19:00 +0300, Ernst, Yehuda wrote:
> I have html with ip addr. inside
> how can i extract it?
> i have in the html 
> <td>x.y.z.w</td>
> where x and y and z and w can be 1 2 or 3 digits.

IP addresses are of the form \d{1,3}(?:\.\d{1,3}){3} so just put that in
whatever capturing regex you need to match the location of the IP
address inside the HTML (don't forget to add \s* everywhere that
appropriate because HTML doesn't mind whitespace, but regular
expressions usually do).

You might also want to consider parsing the HTML using some document
parser and then looking up the DOM tree using DOM traversal or XPath,
instead of using pure regular expression magic.



More information about the Perl mailing list