Question

I have a regex validation rule in aim to check if the user enter valide IP adress in a textarea of 10 lines max. The rules are : IP address must begin with 10.200.X.X and the user can enter 1 to 10 addresses, each address being on one single line (separated with end of line character).

Actually, this regex is working, but it's very very long. Can anyone think about a shortened regular expression wich is working please ?

^(10\.200\.([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))(([\n\r]10\.200\.([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))?){1,9}$

Thanks a lot to everyone

Was it helpful?

Solution

You can try :

^(10\.200\.([1-9]?\d|1\d{2}|2[0-4]\d|25[0-5])\.([1-9]?\d|1\d{2}|2[0-4]\d|25[0-5]))(([\n\r]10\.200\.([1-9]?\d|1\d{2}|2[0-4]\d|25[0-5])\.([1-9]?\d|1\d{2}|2[0-4]\d|25[0-5]))?){1,9}$

Explanation

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top