<br><br><div><span class="gmail_quote">On 9/20/07, <b class="gmail_sendername">Matt McCredie</b> <<a href="mailto:mccredie@gmail.com">mccredie@gmail.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>> Any common knowledge IP matching RE?<br><br>I don't know if there is any common knowledge RE, but I came up with<br>the following:<br><br>r"((1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|\d)\.){3}(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|\d)")
</blockquote><div><br>Thank you. I will use that! <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>I generally discourage people from using REs. I think the folowing is
<br>much easier to read:</blockquote><div><br>Well, I need the regex to be used withing a parser (yeanpypa or ZestyParser),  so I need it to be a regex to be matched against, and not a piece  of code .<br>I could probably use a more simplistic re that does not check numeric validity, and do that later, but your re would do both matching and validation in one step.
<br><br>Dan <br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">def isip(x):<br>    octs = x.split(".")<br>    if len(octs) != 4:
<br>        return False<br>    for oct in octs:<br>        if len(oct) > 1 and oct[0] == "0":<br>            return False<br>        try:<br>            if not 0 <= int(oct) < 256:<br>                return False
<br>        except ValueError:<br>            return False<br>    return True<br><br>Both solutions seem to work, though I used a small set of test cases.<br>Others may have better suggestions.<br><br>Matt<br></blockquote>
</div><br>