21 responses

  1. ChAr
    September 8, 2010

    Hi, I think that in Your second example the “invalid” IP adress is actually perfectly valid one. 243 is NOT greater than maximum of 255.

  2. pedrow
    September 8, 2010

    Can you just check, is your second example right?

  3. Jeroen Pluimers
    September 8, 2010

    This is in fact a much better example than the eternal email address validation (which – when you read the RFC’s closely – can only be approximated by regular expressions).


  4. Michael Justin
    September 9, 2010

    Hint: a simple number like 123456789 is also a valid IP address (if it is in the IPv4 or IPv6 address range). The dot-decimal notation is only the usual representation. Try it with “ping 123456789″.

  5. Atle
    September 9, 2010

    This is wrong:
    “In this case not, the IP address finish with 243, it is out of the range which is 255″..

    243 is not outside the range.

  6. Uwe Raabe
    September 9, 2010

    @Atle: The output actually states that the IP address is correct!

    • Andreano Lanusse
      September 9, 2010

      All sorry, it was a typo from my side, the second example finish with 263 and the output message said DOES NOT match, so the program is correct, again my typo :)

  7. Stefan
    September 9, 2010

    Actually your example checks if the given text *contains* a valid IP adress, not if it *is* a valid IP adress.

    • Andreano Lanusse
      September 9, 2010

      Hi Stefan, it will check if the IP address is valid, as well it will restrict the 4 numbers in the IP address to 0..255.

      But if you are considering if the IP address is valid on the network, not I’m not doing that, you can use the IP works ping component to check that :)

  8. Stefan
    September 9, 2010

    Nope, you are using word boundaries instead of start and end of string anchors. “Hello World” would match the regex.

  9. john
    September 9, 2010

    This post is a good example of why you don’t want regexps in your code: not only it is messy to look at, but it is also obviously hard to figure out if the regexp is correct or not (see the various comments above!)

  10. Andreano Lanusse
    September 10, 2010

    Interesting Stefan, so I had to change the regexp I used to not allow that :)

  11. Andreano Lanusse
    September 10, 2010

    @John, it’s not friendly the regexp mask, but it doesn’t mean it is not useful.

    This is just a example how to use and it is very useful, I could create a separated function and make the code clear putting the regexp mask in other function.

  12. Stefan
    September 10, 2010

    @John: RegExps are very powerful, you have to learn how to use them if you are not familar with them. Prolly a case for solid unit testing.

    @Andreano: Yes, simply change the \b at the beginning to ^ and the \b at the end to $. ;)

  13. john
    September 14, 2010

    Well goto is powerful too, and it can allow to do more with less code, doesn’t mean you want to use it.

    Andreano, compare your regexp with normal Delphi code one would use to do the validation: the code will be simpler, clearer, more maintainable and likely faster.

    • Andreano Lanusse
      September 14, 2010

      I understand John, but you can assume all of your strings will come from Delphi Applications, for example if you have a REST Server and need to get the content of HTML Input, you will need to parse the content which I think you will have more work then only use a RegExp.

      I will blog more about that and will show how to write a clear code using RegExp.

  14. Fabricio
    September 15, 2010

    Andreano, compare your regexp with normal Delphi code one would use to do the validation: the code will be simpler, clearer, more maintainable and likely faster.
    I believe it can clearer and more *readable*. Simpler I have some doubt. And I’m pretty sure that, for getting information on large strings, nothing can be faster than regex… (Unless Emb implementation had done something much wrong).
    Regex is (maybe just one of them) the little secret that makes PERL almost invincible in text processing.

  15. Please Help me!
    October 21, 2010

    Help Me ,My Dear Friend!
    I Want Create A program With Delphi7,that Ping Many Ips in one Time(Real Time).
    please Send for me your Standard Delphi7 request in : Alexander.Alkhine@gmail.com
    thank you.

    • Andreano Lanusse
      October 25, 2010

      Alexander, the ipWorks components included in Delphi XE has many internet components, one of them is the Ping component, it does what are you looking for.

  16. Carl
    July 31, 2011

    How can I use this component for C++ Builder XE? My friend Brent and I are trying to use regex’s to parse content from Web Responses.

Leave a Reply




Back to top
mobile desktop