Regex Substring Question

I am parsing a specific web page for IP address information using the following expression to find an IP address - which always start a given line:

\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b

By itself, this works without any issues - but I need the entire line and the line can be ended by a line break or a closing tag (i.e. </tr>, </div>, </p>, </li>, etc...).  I have tried using groups but nothing I am doing is working.  For example, if the above expression is called IPMatch, I tried:

(IPMatch){1}(.*)(/[tr|p|li|dvi|body|table){1}

This ends up finding the first IP address and then returning the entire page after that point.  Can somebody please help?
ktolaAsked:
Who is Participating?
 
Terry WoodsConnect With a Mentor IT GuruCommented:
Or try:
(IPMatch){1}(.*?)(?:</(?:tr|p|li|div|body|table)>|\n)

Open in new window

0
 
SuperdaveCommented:
If you don't have nested tags that you need to include, you could just take all characters up to <, something like this:

(IPMatch){1}([^<]*)
0
 
ktolaAuthor Commented:
That works perfectly - thank you!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.