Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在学习正则表达式,并希望在 URL 中搜索任何可能的图像扩展名(jpg、jpeg、png、gif .. 等),并且如果 URL 的文件扩展名是图像。
我想%20用加号替换任何或空格+
%20
+
如何才能做到这一点?
www.test.com/this/is/an/image&20with%20spaces.jpg www.test.com/this/is/an/image+with+spaces.jpg
按照我的看法,您必须分两行执行此操作。
Pattern imagePattern = Pattern.compile("\\.(png|gif|jpg|jpeg)$", Pattern.CASE_INSENSITIVE); if (imagePattern.matcher(input).find()) input = input.replaceAll("(%20)|\\s", "+");