I have a requirement to match all the incoming requests and filter out certain requests based on request URL. Currently I’m trying to use a regular expression like /app/webapp/users/*/resource/path to match /app/webapp/users/<some_user_id>/resource/path. But the none of the incoming requests seem to match the regex. What is the problem with the regex I’m trying to use? (I’m using String class’ matches method to do the comparison).
I have a requirement to match all the incoming requests and filter out certain
Share
/*/looks more like a glob than a regex to me. That will match any number of slashes, whereas I expect you want it to match any number of characters between the slashes. Try/.+/instead, or possibly/[^/]+/if you want to make it only match a single level (i.e. if /app/webapp/users/foo/bar/baz/resource/path shouldn’t match).EDIT: As Joachim mentioned, another way of only matching a single level is to use
/.+?/to make it a “reluctant” match.