1

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

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot for your refacto Sujith !! And thank you for your illustration shema, It helps me a lot !! Have a good day

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.