用于提取Classic ASP 包含文件名的正则表达式
Regular expression for extracting Classic ASP include file names
我正在寻找可以帮助我从以下字符串中提取 filename.asp
的 正则表达式 。这似乎是一个简单的任务,但我无法找到解决方案。
这是我的输入:
<!-- #include file="filename.asp" -->
我想要这样的正则表达式输出:
filename.asp
我做了一些研究并找到了以下解决方案。
正则表达式:
/#include\W+file="([^"]+)"/g
示例代码(VB.NET):
Dim list As New List(Of String)
Dim regex = New System.Text.RegularExpressions.Regex("#include\W+file=""([^""]+)""")
Dim matchResult = regex.Match(filetext)
While matchResult.Success
list.Add(matchResult.Groups(1).Value)
matchResult = matchResult.NextMatch()
End While
示例代码 (C#):
var list = new List<string>();
var regex = new Regex("#include\W+file=\"([^\"]+)\"");
var matchResult = regex.Match(fileContent);
while (matchResult.Success) {
list.Add(matchResult.Groups[1].Value);
matchResult = matchResult.NextMatch();
}
改进的正则表达式(忽略空格):
#include\W+file[\s]*=[\s]*"([^"]+)"
我正在寻找可以帮助我从以下字符串中提取 filename.asp
的 正则表达式 。这似乎是一个简单的任务,但我无法找到解决方案。
这是我的输入:
<!-- #include file="filename.asp" -->
我想要这样的正则表达式输出:
filename.asp
我做了一些研究并找到了以下解决方案。
正则表达式:
/#include\W+file="([^"]+)"/g
示例代码(VB.NET):
Dim list As New List(Of String)
Dim regex = New System.Text.RegularExpressions.Regex("#include\W+file=""([^""]+)""")
Dim matchResult = regex.Match(filetext)
While matchResult.Success
list.Add(matchResult.Groups(1).Value)
matchResult = matchResult.NextMatch()
End While
示例代码 (C#):
var list = new List<string>();
var regex = new Regex("#include\W+file=\"([^\"]+)\"");
var matchResult = regex.Match(fileContent);
while (matchResult.Success) {
list.Add(matchResult.Groups[1].Value);
matchResult = matchResult.NextMatch();
}
改进的正则表达式(忽略空格):
#include\W+file[\s]*=[\s]*"([^"]+)"