02-23-2021 10:29 AM
https://regex101.com/ is a great site to test your regexes without having to make a million cases in LabVIEW. It also has an "explanation" panel to the side that gives you some tips on how to use it.
02-23-2021 10:31 AM
@pincpanter wrote:
@Yamaeda ha scritto:
Your solution is great TiTou, but if you want to do it manually this is a solution:
This would make "10. 0. 0. 122" a valid IP, which is questionable (String To IP would refuse to convert).
Not sure if this is enough. It doesn't accept 0001, maybe it should. It does accept 001, not sure it should...
02-23-2021 10:32 AM
@BertMcMahan wrote:
https://regex101.com/ is a great site to test your regexes without having to make a million cases in LabVIEW. It also has an "explanation" panel to the side that gives you some tips on how to use it.
Do mean you make mistakes with reg.ex.? 😉
02-23-2021 10:49 AM - edited 02-23-2021 11:00 AM
wiebe@CARYA ha scritto:
@pincpanter wrote:
@Yamaeda ha scritto:
Your solution is great TiTou, but if you want to do it manually this is a solution:
This would make "10. 0. 0. 122" a valid IP, which is questionable (String To IP would refuse to convert).
Not sure if this is enough. It doesn't accept 0001, maybe it should. It does accept 001, not sure it should...
It probably depends on the context.
Just tried with Titou's code: 100.23.45.67 is translated back to the same address, but 0100.023.045.067 is translated back to 64.19.37.55 (as is 00100.0023.0045.0067). That means that any trailing 0 makes the function interpret the number as octal.
[Edit: as clearly stated in the help, of course: but I never noticed this]
02-23-2021 11:56 AM
The farther this discussion goes, the more I like the original alternative:
@TiTou wrote:
-Kevin P
02-23-2021 12:26 PM
wiebe@CARYA wrote:
(([012]?[0-9][0-9])|([0-9]?[0-9]))\.(([012]?[0-9][0-9])|([0-9]?[0-9]))\.(([012]?[0-9][0-9])|([0-9]?[0-9]))\.(([012]?[0-9][0-9])|([0-9]?[0-9]))
Matches some none IP V4 numbers like 292.168.1.5
I use the PCRE
\A(?:(?:\d|\d\d|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d|\d\d|1\d\d|2[0-4]\d|25[0-5])\Z
02-23-2021 12:41 PM - edited 02-23-2021 12:42 PM
I faintly remember entries in the forum where the IP to String function had side effects on the network stack, freezing VIs.
.NET should work fine (https://docs.microsoft.com/en-us/dotnet/api/system.net.ipaddress.parse?view=net-5.0)
Also, just for completenesses sake: The task to validate an IP address by regex is so common it even has its own website: http://ipregex.com/
02-23-2021 12:50 PM
wiebe@CARYA wrote:
It doesn't accept 0001, maybe it should. It does accept 001, not sure it should...
Leading zeros are acceped sometimes. Leading zeros are not allowed, they are used for octal notation.
02-24-2021 05:50 AM
@Martin_Henz wrote:
wiebe@CARYA wrote:
It doesn't accept 0001, maybe it should. It does accept 001, not sure it should...
Leading zeros are acceped sometimes. Leading zeros are not allowed, they are used for octal notation.
Hm..
If the reg.ex. is to support octal numbers, it's going to be even more complex.
I have used the string to IP trick before.
The string also accept "localhost", and IP to string will turn that into 127.0.0.1 or the PC's name (depending on the notation).
The string also accepts resolvable PC names, and even URLs. "www.google.com" resolves to 142.250.179.132, for instance.
If the goal is to validate a dot notation, it works. Except for octal inputs.
If the goal is to validate the string as a valid address, the IP to string output should be tested against 255.255.255.255 and 0.0.0.0.
Hard stuff...
02-24-2021 09:17 AM - edited 02-24-2021 09:19 AM
TLDR;
Here's how I check for a valid IP address.
LOL, I just noticed someone already posted MY CODE!
I will take that as a compliment 😛