Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex to match S3 file and a directory

Tags:

java

regex

I have the following pattern that used to match a S3 URL

Pattern.compile("^s3://([^/]+)/(.*?([^/]+))$");

This matches

s3://bucket/path/key

But does not match a directory

s3://bucket/path/directory/

Is there an easy way to change the pattern to match a directory?

like image 389
rakeshr Avatar asked Oct 22 '25 15:10

rakeshr


1 Answers

There's only the final slash missing in the regex. You might try this:

^s3://([^/]+)/(.*?([^/]+)/?)$
                         ^^

regex101 demo.

like image 126
Jerry Avatar answered Oct 25 '25 06:10

Jerry



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!