开发者

Library to clean up and simplify filenames?

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 wa开发者_Go百科s 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-_\\.]", "_")

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜