java - Regex does not properly break down file path with a version number -


I was using a regex pattern to break the reference path for the servlet.

  / {1,2} ([^ / {1,2}) +)  

This works very well for simple code like / user / folder1 / folder2 / folder3 / .

In more real-world scenarios, if there is a dotted version number in a folder name such as: / user / usernames / library / tomacat / apache-tomcat-6.0.24 .

In this case Matcher.group (1) back apache-tomcat-6.0. instead of Apache-Badge-6.0.24 . I do not know why this happens; I believe this should not be.

Any insights?

Edit

This works:

  / {1,2} ([^ /] + )  

[^ / {1,2}] Except every code, / , {, 1 , , , 2 and more } ", therefore 2 of 24 did not match (this would be as a path like a / 2 And that version is not related to numbers). Inside [...] , most letters have a literal meaning, and such as {1,2} do not work. I think that if you only ask [^ /] + then it should work. I'm not sure why you want to consistently match two slashes - just match with a slash and filter empty directory names.


Comments