Passing regex as a parameter in my REST web service

What I would like to do is pass the regular express for my second parameter. For instance:

  • . * \\. Txt
  • . * 2010. * \\. Txt
@RequestMapping(value = "/filesCleanUp/{confParamName}/{pattern}", method = RequestMethod.GET) public ResponseEntity<String> doFilesCleanUp(@PathVariable("confParamName") String confParamName, @PathVariable("pattern") String pattern) 

This is how I call the service:

  • /filesCleanUp/param1/.* \\. Txt
  • /filesCleanUp/param1/.* 2010. * \\. Txt

But this does not work, the template does not work correctly from the URL. For the first I get ". * \\", and for the second - ". * 2010. * \\"

I conducted other tests with different values:

  • the pattern is written in URL: \ (. * l
    I got:\(

  • pattern wrote in the URL: (2 \. [0-3]))
    I got: (2 \

Usually it is confused with characters like * or.

I am sure this is nothing, but I can’t find out. I would like to get the exact template I wrote

thanks for the help

+4
source share
1 answer

If you really want to pass such parameters (which I highly recommend), please refer to http://perishablepress.com/how-to-write-valid-url-query-string-parameters/

Otherwise, encode and publish them and decode back on the server side.

0
source

All Articles