Regular expression to match DNS hostname or IP Address?

后端 未结 21 2999
长发绾君心
长发绾君心 2020-11-21 07:25

Does anyone have a regular expression handy that will match any legal DNS hostname or IP address?

It\'s easy to write one that works 95% of the time, but I\'m hoping

21条回答
  •  庸人自扰
    2020-11-21 07:57

    I found this works pretty well for IP addresses. It validates like the top answer but it also makes sure the ip is isolated so no text or more numbers/decimals are after or before the ip.

    (?

提交回复
热议问题