I am developing a RESTFUL server in spring-boot. For one of the rest endpoint that I am developing, the user will pass IP address as path variable. I want to validate whether the parameter passed contains valid IP address or not. One of the ways that I know is to use regex in request mapping. I have tried but it gives an error.
Request Mapping:
@GetMapping("/{citycode:[0-9]{3}+}/{zoneno:[0-9]{5}+}/device/info/{deviceIP:^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)}")
Error:
java.lang.IllegalArgumentException: The number of capturing groups in the pattern segment (((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)) does not match the number of URI template variables it defines, which can occur if capturing groups are used in a URI template regex. Use non-capturing groups instead.
My another concern is, regex for IP is quite long and it turns my request mapping look dirty. Is there any other way to valid IP in request mapping?