0

Hi,

Can you tell me what is the regular expression for a comma-separated list (in this case - IPs) ?
My list looks like this:

192.168.0.1, 10.%.23.100, %.46.%.1

So far I managed to create this:

^[0-9%]{1,3}.[0-9%]{1,3}.[0-9%]{1,3}.[0-9%]{1,3}$

But I don't know how to specify a comma-separated list of the above sequence.

Thanks,
Ender

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by Taywin
0

Maybe I am not understanding what you want to do, but why not split the string on the comma?

if you do this:

var str="123.25.12.135,15.45.85.12,25.85.45.58";


var array = str.split(",");

for(wordIndex in array)
{
     //array[wordIndex] is each individual address
     //run REGEX on each one to determine if it is valid or whatever you are planning

}

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

0

Better yet... str.split(/\s*,\s*/) which will get rid of white spaces before and after comma... This would take care of "ab,c, de , g,h,i" as an array with elements ["ab", "c", "de", "g", "h", "i"] instead of ["ab", "c", " de ", " g", "h", i"] as the suggested above post. Though, the above post is going on the right track. :)

PS: This thread is almost a month old already!!!

Edited by Taywin: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.