[Solved] Regex to match /src/main/{any_package}/*.java

Maybe, this expression would also function here, even though your original expression is OK. ^\/src\/main\/java(\/[^\/]+)?\/\*\.java$ Demo 1 My guess is that here we wish to pass: /src/main/java/{any_package}/*.java /src/main/java/*.java If the second one is undesired, then we would simply remove the optional group: ^\/src\/main\/java(\/[^\/]+)\/\*\.java$ Demo 2 and it might still work. Test import java.util.regex.Matcher; import java.util.regex.Pattern; … Read more