问题描述
我需要一个正则表达式来验证字符串是否为IP地址。 (它是一个正确的 IP地址并不重要;这只是一个快速的错误检查,以确保它是那种格式。)这是我到目前为止。它会工作吗?
^ \d {1,3} \.\d {1,3} \。\d {1,3} \.\d {1,3} $
我能解决的问题看来是它没有验证每个数字是否小于256(例如,你可以输入999.999.999.999),但我不知道如何将正则表达式与数学表达式结合起来,我认为更多的是房间改善情况而不是关键问题。
I need a regular expression to verify that a string is an IP address. (It's not critical that it be a correct IP address; this is just a quick error check to make sure it's in that format.) This is what I have so far. Will it work all right?
^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$
The problem I can see is that it doesn't verify that each number is less than 256 (eg, you could enter 999.999.999.999), but I don't know how to combine regular expressions with mathematical ones, and I consider that more of a "room for improvement" situation than a critical problem.
这篇关于这个正则表达式是否适用于IP验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!