Java正则表达式:在字符串中替换特定类型的url?
样本输入:
"http://bits.wikimedia.org/w/extensions-1.17/MobileFrontend/stylesheets/webkit.css"
我的尝试:"http://.*?/stylesheets/webkit.css"
未找到任何匹配项
在"http://"
和"webkit.css"
之间的url部分是可变的
谢谢
糟糕的是,我使用的是Java的replace()函数,而不是replaceFirst()或replaceAll()
# 1 楼答案
一种解决方案是使用分组:
结果将等于
http://example.com/stylesheets/webkit.css
另一个选项是使用环顾四周:
上面写着“用
replacement
替换http://
和/stylesheets/webkit.css
之间的所有内容。”