I'd like to convert filenames that have spaces and symbols to contain only the characters A-Z, a-z, a period, a hyphen, and an underscore. Something like this regex: ([a-z][A-Z]-_\.)+
Of course, I could just do this with a regex. But since I've already including many libraries in my project (Spring, Hibernate, Apache Commons, and much more), I was wondering if something like this is already available.
So a string like this:
This>is some(string,with $invalid*-chars).jpg
Would be converted to this:
This_is_some_string_with__invalid_-chars_.jpg
No library is going to be able to offer you something simpler than String.replaceAll("[^a-zA-Z0-9-_\\.]", "_")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With