Skip to content
Advertisement

Using a RegEx to match IP addresses

I’m trying to make a test for checking whether a sys.argv input matches the RegEx for an IP address…

As a simple test, I have the following…

JavaScript

However when I pass random values into it, it returns “Acceptable IP address” in most cases, except when I have an “address” that is basically equivalent to d+.

Advertisement

Answer

You have to modify your regex in the following way

JavaScript

that’s because . is a wildcard that stands for “every character”

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement