任何人都可以请解释我这个正则表达式的含义吗?正则表达式的解释
/^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$/
任何人都可以请解释我这个正则表达式的含义吗?正则表达式的解释
/^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$/
我认为这正则表达式将验证IPv4地址
请使用此链接以获得正则表达式
NODE EXPLANATION -------------------------------------------------------------------------------- ^ the beginning of the string -------------------------------------------------------------------------------- ( group and capture to \1: -------------------------------------------------------------------------------- [1-9] any character of: '1' to '9' -------------------------------------------------------------------------------- | OR -------------------------------------------------------------------------------- [1-9] any character of: '1' to '9' -------------------------------------------------------------------------------- [0-9] any character of: '0' to '9' -------------------------------------------------------------------------------- | OR -------------------------------------------------------------------------------- 1 '1' -------------------------------------------------------------------------------- [0-9] any character of: '0' to '9' -------------------------------------------------------------------------------- [0-9] any character of: '0' to '9' -------------------------------------------------------------------------------- | OR -------------------------------------------------------------------------------- 2 '2' -------------------------------------------------------------------------------- [0-4] any character of: '0' to '4' -------------------------------------------------------------------------------- [0-9] any character of: '0' to '9' -------------------------------------------------------------------------------- | OR -------------------------------------------------------------------------------- 25 '25' -------------------------------------------------------------------------------- [0-5] any character of: '0' to '5' -------------------------------------------------------------------------------- ) end of \1 -------------------------------------------------------------------------------- ( group and capture to \2 (3 times): -------------------------------------------------------------------------------- . any character except \n -------------------------------------------------------------------------------- ( group and capture to \3: -------------------------------------------------------------------------------- [0-9] any character of: '0' to '9' -------------------------------------------------------------------------------- | OR -------------------------------------------------------------------------------- [1-9] any character of: '1' to '9' -------------------------------------------------------------------------------- [0-9] any character of: '0' to '9' -------------------------------------------------------------------------------- | OR -------------------------------------------------------------------------------- 1 '1' -------------------------------------------------------------------------------- [0-9] any character of: '0' to '9' -------------------------------------------------------------------------------- [0-9] any character of: '0' to '9' -------------------------------------------------------------------------------- | OR -------------------------------------------------------------------------------- 2 '2' -------------------------------------------------------------------------------- [0-4] any character of: '0' to '4' -------------------------------------------------------------------------------- [0-9] any character of: '0' to '9' -------------------------------------------------------------------------------- | OR -------------------------------------------------------------------------------- 25 '25' -------------------------------------------------------------------------------- [0-5] any character of: '0' to '5' -------------------------------------------------------------------------------- ) end of \3 -------------------------------------------------------------------------------- ){3} end of \2 (NOTE: because you are using a quantifier on this capture, only the LAST repetition of the captured pattern will be stored in \2) -------------------------------------------------------------------------------- $ before an optional \n, and the end of the string
的explation虽然上述回答按原子解释正则表达式原子,我认为你是答案寻找的是“它匹配IPv4地址”。
要机智:
# Match the beginning of a string
/^
# Match a number from 1-255
([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])
# Same as above with a . in front of it
(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]))
# Match the above three times.
{3}
# Match end of the string
$/
它与IP地址匹配吗? – Geezer68
@csmckelvey是的,我认为它验证IPv4地址 –
我不知道,但你只是调试所有这些垃圾PHP脚本我解码微风....谢谢你!评论中的链接的总赞成数。 –