Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring MVC 3 RequestMapping with regular expresssion quantifiers

The method below fails with "PatternSyntaxException: Unclosed counted closure near index ... "

@RequestMapping(value ="/{id:[0-9|a-z]{15}}")
public View view(@PathVariable final String id) {
  ...
}

Looks like the pattern matcher is trimming too much off the the string and losing the last }.

Does anyone know a work around to this bug? I'm having to drop the qualifier to "/{id:[0-9|a-z]+}" - which frankly suck!

like image 856
dom farr Avatar asked Aug 23 '26 17:08

dom farr


1 Answers

Here's a solution. It's butt-ugly, but it's equivalent to what you'd like to have:

@RequestMapping(value = "/{id:[0-9a-z][0-9a-z][0-9a-z][0-9a-z]" +
        "[0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z]" +
        "[0-9a-z][0-9a-z][0-9a-z][0-9a-z]}") // 15 repetitions of [0-9a-z]

If that's the only way to get what you need, you might as well use this monster.

like image 144
Sean Patrick Floyd Avatar answered Aug 26 '26 09:08

Sean Patrick Floyd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!