Comments on: Using regular expressions to validate IP address with Delphi XE http://www.andreanolanusse.com/en/using-regular-expressions-to-validate-ip-address-with-delphi-xe/ Where Andreano Lanusse talk about technology, software development, programming techniques, databases, games and more through articles, tutorials and videos Thu, 12 Jan 2012 07:59:45 +0000 hourly 1 https://wordpress.org/?v=6.7.4 By: Andreano Lanusse http://www.andreanolanusse.com/en/using-regular-expressions-to-validate-ip-address-with-delphi-xe/#comment-10320 Thu, 12 Jan 2012 07:59:45 +0000 http://www.andreanolanusse.com/en/?p=349#comment-10320 In reply to Carl.

Carl,

You can use RegExp in C++ as I describe in this blog post http://www.andreanolanusse.com/en/using-regular-expression-on-cbuilder-firemonkey-application/

]]>
By: Carl http://www.andreanolanusse.com/en/using-regular-expressions-to-validate-ip-address-with-delphi-xe/#comment-9177 Sun, 31 Jul 2011 15:15:38 +0000 http://www.andreanolanusse.com/en/?p=349#comment-9177 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.

]]>
By: Andreano Lanusse http://www.andreanolanusse.com/en/using-regular-expressions-to-validate-ip-address-with-delphi-xe/#comment-4192 Tue, 26 Oct 2010 04:15:07 +0000 http://www.andreanolanusse.com/en/?p=349#comment-4192 In reply to Please Help me!.

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.

]]>
By: Please Help me! http://www.andreanolanusse.com/en/using-regular-expressions-to-validate-ip-address-with-delphi-xe/#comment-4132 Thu, 21 Oct 2010 16:35:21 +0000 http://www.andreanolanusse.com/en/?p=349#comment-4132 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.

]]>
By: Fabricio http://www.andreanolanusse.com/en/using-regular-expressions-to-validate-ip-address-with-delphi-xe/#comment-3776 Wed, 15 Sep 2010 17:22:28 +0000 http://www.andreanolanusse.com/en/?p=349#comment-3776 @John
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.

]]>
By: Andreano Lanusse http://www.andreanolanusse.com/en/using-regular-expressions-to-validate-ip-address-with-delphi-xe/#comment-3763 Tue, 14 Sep 2010 19:40:39 +0000 http://www.andreanolanusse.com/en/?p=349#comment-3763 In reply to john.

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.

]]>
By: john http://www.andreanolanusse.com/en/using-regular-expressions-to-validate-ip-address-with-delphi-xe/#comment-3756 Tue, 14 Sep 2010 12:10:17 +0000 http://www.andreanolanusse.com/en/?p=349#comment-3756 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.

]]>
By: Stefan http://www.andreanolanusse.com/en/using-regular-expressions-to-validate-ip-address-with-delphi-xe/#comment-3702 Fri, 10 Sep 2010 18:13:36 +0000 http://www.andreanolanusse.com/en/?p=349#comment-3702 @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 $. 😉

]]>
By: Andreano Lanusse http://www.andreanolanusse.com/en/using-regular-expressions-to-validate-ip-address-with-delphi-xe/#comment-3699 Fri, 10 Sep 2010 13:51:17 +0000 http://www.andreanolanusse.com/en/?p=349#comment-3699 @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.

]]>
By: Andreano Lanusse http://www.andreanolanusse.com/en/using-regular-expressions-to-validate-ip-address-with-delphi-xe/#comment-3698 Fri, 10 Sep 2010 13:48:30 +0000 http://www.andreanolanusse.com/en/?p=349#comment-3698 Interesting Stefan, so I had to change the regexp I used to not allow that 🙂

]]>
By: john http://www.andreanolanusse.com/en/using-regular-expressions-to-validate-ip-address-with-delphi-xe/#comment-3695 Fri, 10 Sep 2010 06:45:50 +0000 http://www.andreanolanusse.com/en/?p=349#comment-3695 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!)

]]>
By: Stefan http://www.andreanolanusse.com/en/using-regular-expressions-to-validate-ip-address-with-delphi-xe/#comment-3683 Thu, 09 Sep 2010 12:59:53 +0000 http://www.andreanolanusse.com/en/?p=349#comment-3683 Nope, you are using word boundaries instead of start and end of string anchors. “Hello 127.0.0.1 World” would match the regex.

]]>
By: Andreano Lanusse http://www.andreanolanusse.com/en/using-regular-expressions-to-validate-ip-address-with-delphi-xe/#comment-3682 Thu, 09 Sep 2010 12:49:48 +0000 http://www.andreanolanusse.com/en/?p=349#comment-3682 In reply to Stefan.

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 🙂

]]>
By: Stefan http://www.andreanolanusse.com/en/using-regular-expressions-to-validate-ip-address-with-delphi-xe/#comment-3681 Thu, 09 Sep 2010 12:21:03 +0000 http://www.andreanolanusse.com/en/?p=349#comment-3681 Actually your example checks if the given text *contains* a valid IP adress, not if it *is* a valid IP adress.

]]>
By: Andreano Lanusse http://www.andreanolanusse.com/en/using-regular-expressions-to-validate-ip-address-with-delphi-xe/#comment-3680 Thu, 09 Sep 2010 12:01:18 +0000 http://www.andreanolanusse.com/en/?p=349#comment-3680 In reply to Uwe Raabe.

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 🙂

]]>
By: Uwe Raabe http://www.andreanolanusse.com/en/using-regular-expressions-to-validate-ip-address-with-delphi-xe/#comment-3679 Thu, 09 Sep 2010 08:47:15 +0000 http://www.andreanolanusse.com/en/?p=349#comment-3679 @Atle: The output actually states that the IP address is correct!

]]>
By: Atle http://www.andreanolanusse.com/en/using-regular-expressions-to-validate-ip-address-with-delphi-xe/#comment-3678 Thu, 09 Sep 2010 08:24:40 +0000 http://www.andreanolanusse.com/en/?p=349#comment-3678 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.

]]>
By: Michael Justin http://www.andreanolanusse.com/en/using-regular-expressions-to-validate-ip-address-with-delphi-xe/#comment-3677 Thu, 09 Sep 2010 08:03:06 +0000 http://www.andreanolanusse.com/en/?p=349#comment-3677 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”.

]]>
By: Jeroen Pluimers http://www.andreanolanusse.com/en/using-regular-expressions-to-validate-ip-address-with-delphi-xe/#comment-3676 Thu, 09 Sep 2010 07:43:33 +0000 http://www.andreanolanusse.com/en/?p=349#comment-3676 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).

–jeroen

]]>
By: pedrow http://www.andreanolanusse.com/en/using-regular-expressions-to-validate-ip-address-with-delphi-xe/#comment-3675 Thu, 09 Sep 2010 07:31:43 +0000 http://www.andreanolanusse.com/en/?p=349#comment-3675 Can you just check, is your second example right?

]]>