Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 正则表达式的解释_Regex - Fatal编程技术网

Regex 正则表达式的解释

Regex 正则表达式的解释,regex,Regex,谁能解释一下这个正则表达式的含义吗 /^([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地址 请使用此链接获取您的正则表达式的解释 节点解释 ---------------------------------------------------------------------------

谁能解释一下这个正则表达式的含义吗

/^([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地址

请使用此链接获取您的正则表达式的解释

节点解释 -------------------------------------------------------------------------------- ^字符串的开头 -------------------------------------------------------------------------------- (组和捕获到\1: -------------------------------------------------------------------------------- [1-9]任何“1”到“9”的字符 -------------------------------------------------------------------------------- |或 -------------------------------------------------------------------------------- [1-9]任何“1”到“9”的字符 -------------------------------------------------------------------------------- [0-9]任何“0”到“9”的字符 -------------------------------------------------------------------------------- |或 -------------------------------------------------------------------------------- 1 '1' -------------------------------------------------------------------------------- [0-9]任何“0”到“9”的字符 -------------------------------------------------------------------------------- [0-9]任何“0”到“9”的字符 -------------------------------------------------------------------------------- |或 -------------------------------------------------------------------------------- 2 '2' -------------------------------------------------------------------------------- [0-4]从“0”到“4”的任何字符 -------------------------------------------------------------------------------- [0-9]任何“0”到“9”的字符 -------------------------------------------------------------------------------- |或 -------------------------------------------------------------------------------- 25 '25' -------------------------------------------------------------------------------- [0-5]任何“0”到“5”的字符 -------------------------------------------------------------------------------- )结束\1 -------------------------------------------------------------------------------- (分组并捕获到\2(3次): -------------------------------------------------------------------------------- .除以下字符以外的任何字符\n -------------------------------------------------------------------------------- (分组并捕获到\3: -------------------------------------------------------------------------------- [0-9]任何“0”到“9”的字符 -------------------------------------------------------------------------------- |或 -------------------------------------------------------------------------------- [1-9]任何“1”到“9”的字符 -------------------------------------------------------------------------------- [0-9]任何“0”到“9”的字符 -------------------------------------------------------------------------------- |或 -------------------------------------------------------------------------------- 1 '1' -------------------------------------------------------------------------------- [0-9]任何“0”到“9”的字符 -------------------------------------------------------------------------------- [0-9]任何“0”到“9”的字符 -------------------------------------------------------------------------------- |或 -------------------------------------------------------------------------------- 2 '2' -------------------------------------------------------------------------------- [0-4]从“0”到“4”的任何字符 -------------------------------------------------------------------------------- [0-9]任何“0”到“9”的字符 -------------------------------------------------------------------------------- |或 -------------------------------------------------------------------------------- 25 '25' -------------------------------------------------------------------------------- [0-5]任何“0”到“5”的字符 -------------------------------------------------------------------------------- )结束\3 -------------------------------------------------------------------------------- ){3} 结束\2(注意:因为您正在使用 量词在此捕获,只有最后一个 捕获模式的重复将被删除 存储在\2)中 -------------------------------------------------------------------------------- $在可选的前\n和 一串
虽然上面的答案逐原子解释了正则表达式,但我认为您要寻找的答案是“它匹配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
$/
# 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
$/