Search code examples
javaregexreplaceall

JAVA: replaceAll reg pattern


Considering the following string:

String s = "/static/201105-3805-somerandom/images/optional-folder/filename.gif";

How can I remove the "static/201105-3805-somerandom/" part? The "201105-3805-somerandom" part is completely random but always is composed of: - 6 digits - the "-" char - {1, n} digit chars - the "-" char - {1, n} digit and letter chars

If I use "/static/[0-9]*-[0-9]*-*/";, it replaces everything to the last / instead of the one just after the "{1, n} digit and letter chars", what am I missing?


Solution

  • s = s.replaceAll("^/static/\\d{6}-\\d{1,}-.*?/","")