最近有个需求要把图片路径重写一下,本人正则渣渣水平,怎么用正则匹配替换所有的图片路径就成了难题。需求是这样的

费了死劲了写出一个方案:

System.Text.RegularExpressions.Regex.Replace(@"src=""/images/uploadedFiles/20160411160707802.jpeg""", @"src=['""].+?images/(.+?)['""]", @"src=""/GetImage/${1}""", System.Text.RegularExpressions.RegexOptions.IgnoreCase).Replace('/','-').Replace('.','_').Replace("-GetImage", "/GetImage")

亲测可用,但是感觉好麻烦,不是最好的方案,求各位大神指点~

 

相关文章:

  • 2021-10-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-20
  • 2022-01-07
  • 2021-11-24
  • 2021-08-05
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-01
相关资源
相似解决方案