简体   繁体   English

使用正则表达式和VS Replace选项更新Asp.NET Project中的href

[英]Update href in Asp.NET Project using Regular expressions and VS Replace option

I have project on Asp.NET Web Forms. 我在Asp.NET Web窗体上有项目。

I need to update hrefs on Views. 我需要更新Views的hrefs。 This hrefs is for Downloading, so on click user are able to save document, in my case .pdf files. 这个hrefs是供下载的,因此单击用户就可以保存文件,在我的情况下是.pdf文件。 So i need to change href-Links just for target pdf-files 所以我只需要为目标pdf文件更改href-Links

Example : Now href is in next format: 示例:现在href是下一种格式:

href="/about/news/downloads/Ingram%20Announcement_5.31.07.pdf"

What is needed : Add 需要什么:添加

<%=MyProject.Core.Common.PublisherConfigurationManager.Content%>

instead of first / in href link (possible href link hasn't / as first symbol). 而不是第一个/ in href链接(可能的href链接没有/作为第一个符号)。

Expected result is: 预期结果是:

href="<%=MyProject.Core.Common.PublisherConfigurationManager.Content%>
    about/news/downloads/Ingram%20Announcement_5.31.07.pdf"

How can i make this update using Ctrl + Shift + F and Regex? 如何使用Ctrl + Shift + F和Regex进行此更新?

Work in VS 2013 在VS 2013中工作

This will match any href ending in ".pdf". 这将匹配任何以“ .pdf”结尾的href。

Regex: href\\=\\"/?([^"]+\\.pdf)\\" . 正则表达式: href\\=\\"/?([^"]+\\.pdf)\\"

Note this will match the optional / but not capture it. 请注意,这将与可选的/匹配,但不会捕获它。 Then it finds at least 1 character which is not a quote to close the href and ends with .pdf" . The path without the leading / and filename are then stored in match position $1 然后,它找到至少一个不是引号的字符以关闭href并以.pdf"结尾。然后,不带前导/和文件名的路径存储在匹配位置$ 1

Replacement: href="<%=MyProject.Core.Common.PublisherConfigurationManager.Content%>$1" 替换: href="<%=MyProject.Core.Common.PublisherConfigurationManager.Content%>$1"

If you want to match other extensions in addition to pdfs, you can just add an OR clause | 如果要匹配除pdf之外的其他扩展名,则只需添加OR子句| to the regex. 到正则表达式。 For example href\\=\\"/?([^"]+\\.(pdf|jpg))\\" will match pdfs and jpgs. The replacement does not need to change 例如href\\=\\"/?([^"]+\\.(pdf|jpg))\\"将与pdf和href\\=\\"/?([^"]+\\.(pdf|jpg))\\"匹配。替换无需更改

ctrl + h并在搜索词中输入href="/替换词中输入href="/ href="<%=MyProject.Core.Common.PublisherConfigurationManager.Content%>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM