Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

What is regex for this?

Last post 04-20-2011, 11:22 PM by Aussie Susan. 7 replies.
Sort Posts: Previous Next
  •  04-19-2011, 7:44 AM 80965

    What is regex for this?

    If you want to parse all the sets of numbers on a page that look like this:

     

    21.234.571.21:8080

    231.12.9.678:215

     

    How would you go about doing it?

     

    Is this OK?

     

    [0-999].[0-999].[0-999].[0-999]:[0-9999]

     

    Or is this not regex? I've tried it to form a regexp of expressions that start with and end with these features (instead of the typical before and after regex)  but it's not working and would greatly appreciate a little push. thanks.

  •  04-19-2011, 10:02 AM 80970 in reply to 80965

    Re: What is regex for this?

    have u tried to find regex for IP addresses in our library?

  •  04-19-2011, 7:18 PM 80988 in reply to 80965

    Re: What is regex for this?

    Following on from Sergei's advice, I see from your pattern that you have the wrong (but common) understnading of how character set definitions work. Can I suggest that youi read Michael Ash's blog entry at http://regexadvice.com/blogs/mash/archive/2008/01/31/A-touch-of-Character-Class.aspx to learn more about how these are used.

    Susan

  •  04-19-2011, 8:30 PM 80990 in reply to 80988

    Re: What is regex for this?

    Hi guys thanks for your responses. I have indeed tried out http://regexlib.com/Search.aspx?k=ip%20address but maybe there are different types of Regex and Zennoposter uses one that isn't there.

    ZP comes with quick regexpressions, like:

     (\d{1,3}\.){3}\d{1,3}

    for proxies, and it works, finally a regex that works!!!: Can I ask you guys what regexp type is this, and given this what would you add to the end to add the port? thanks, will read the post entry, indeed mebbe the entire blog..

  •  04-19-2011, 11:37 PM 80996 in reply to 80990

    Re: What is regex for this?

    Will the port always be there or is it optional (I've assumed optional below)? Also, how many digits will there be in the port number (I've assumed 5 below)?

    Try

    (\d{1,3}\.)\d{1,3}(:\d{1,5})?

    Susan

  •  04-20-2011, 5:05 AM 80998 in reply to 80996

    Re: What is regex for this?

    thanks, that works very nicely susan.

     

    I'm still struggling a lot with regexp using things like Expresso, so would you mind if i ask you how you'd get the following into regular expression:

     

    ?t=53578

     

    the numbers will vary and the t will be different letters of the alphabet. But I haven't figured out how to get a ? or a = into regexp yet. thanks.

  •  04-20-2011, 7:58 PM 81005 in reply to 80998

    Re: What is regex for this?

    actually nevermind, i really should learn to relax a little, looked it up in regular-expressions.info and expresso and built it in no time. \?t\=\d{5}

  •  04-20-2011, 11:22 PM 81008 in reply to 81005

    Re: What is regex for this?

    You  actually don't need to escape the '=': it does not do any harm to use the escape, but it does end up making the pattern harder to read - especially if you need to write the pattern as a string where the "\' character itself needs to be escaped (your pattern would then end up looking like "\\?t\\=\\d{5}").

    Susan

View as RSS news feed in XML