I think you can do this easier with the parsed URI object you receive, which is already doing the splitting for you. You basically want to check that the scheme is s3, the host exists, and the path exists, right?