I have regex for IPv4 address:
^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$
and i have regex for IPv4 CIDR range :
^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(/([0-9]|[1-2][0-9]|3[0-2]))$
the issue is how should i repeat it using comma separated
pattern:
XXX.XXX.XXX.XXX, XXX.XXX.XXX.XXX/XX, XX.XX.XX.XX, XX.XX.XX.XX/X , XX.XX.XX.X test data--
123.123.13.11, 1.0.0.0, 1.0.0.1/3, 1.0.0.0/20
am using http://regexr.com/ to build by regex, the regex which i build is below and not working--
/(((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))),?)/g
To loop surround regex with
()*ex(<regex>)*if matching start and end then move terminators out of loop like^(regex)*$To match
,or end-of-line append([,\s]+|$)exclude\sif you don't want whitespace,+means match one or more.This should work for you to match the whole string. Remove
*at end for valid parts; surround with ^ $ to match full string.Or, for minimal group matching
((?!\\/)is negative look ahead for/, not all regex engines support negative look ahead)