[英]How to pull the filenames from an .htm file using PowerShell's select-string?
I am trying to search through the .htm files for our intranet to find out which network files are being linked to on which pages of the site. 我正在尝试搜索.htm文件中的内部网,以找出哪些网络文件链接到该站点的哪些页面。 What I would like to do is have PowerShell go through each .htm and return any string that begins with "file:///" and ends with a double quote.
我想要做的是让PowerShell遍历每个.htm并返回以“file:///”开头并以双引号结尾的任何字符串。 For instance:
例如:
<td colspan="3"><a href="file:///X:/Name of Document.doc" style="text-decoration: none">
Would return: 会回来:
file:///X:/Name of Document.doc
As for the PowerShell commands, I have been using this: 至于PowerShell命令,我一直在使用它:
select-string -Path [Document Path] -Pattern '[Pattern]' -AllMatches | % { $_.Matches } | % { $_.Value }
The only trouble I am running into is that I cannot figure out the regular expression that I should be using to pull the strings that I am looking for. 我遇到的唯一麻烦是我无法弄清楚我应该使用的正则表达式来拉动我正在寻找的字符串。 Any ideas?
有任何想法吗?
This pattern should work: `file:///[^"]*' eg: 这种模式应该有效:`file:/// [^“] *'例如:
$str = @'
<td colspan="3">
<a href="file:///X:/Name of Document.doc" style="text-decoration: none">
'@
$str | select-string '(file:///[^"]*)' | %{$_.Matches[0].Value}
file:///X:/Name of Document.doc
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.