-2

我正在混合链接回不同文件类型的 URL。我想使用 RegEx 删除匹配的 URL .pdf,但是我不确定如何在不影响URL 的.html情况下执行此操作。.ppt .doc

http://www.myurl.com/library/mydocument.doc
http://www.myurl.com/library/somefile.pdf

我尝试了此处发布的不同示例,但它们适用于 Java 和 C#,因此它们不起作用。

谢谢您的帮助

编辑

我正在使用基于.NET 的Nintex RegEx。我完全没有 C#、Java、.NET 等方面的经验......

我目前正在从包含不同文件类型结尾的 SharePoint 中提取库 URL。我能够弄清楚如何删除不需要的文件类型,但是它仍然给我带来了问题。

这是我的以下布局

pattern = `.*pdf.*|.*pptx.*|`

Replacement = 

问题是我得到空行的 CRLF。然后我尝试了以下

pattern = `.*pdf.*|.*pptx.*|[\r\n]*`
Replacement = 

问题是一旦我添加了删除 CRLF,它会将所有字符串放在一行中。

4

2 回答 2

2

在 .NET 中过滤掉文件扩展名时,您可以使用Path.GetExtension

例子:

using System.IO;
class Program
{
    static void Main(string[] args)
    {
        string[] files = new string[3]
        {
            "http://www.myurl.com/library/mydocument.doc",
            @"C:\files\somefile.pdf",
            "someotherfile.pdf",
        };

        List<string> filteredFiles = new List<string>(); 
        foreach (string file in files)
        {
            if (Path.GetExtension(file) != ".pdf")
            {
                filteredFiles.Add(file);
                Console.WriteLine(file);
            }
        }
        Console.Read();
    }
}
于 2015-07-30T17:48:48.077 回答
0

此模式仅适用于最终以 pdf 和可能的空格结尾的 http(s)。

string data = @"alphapdf
http://www.myurl.com/library/mydocument.doc
http://www.myurl.com/library/somefile.pdf
Gamma";

string pattern = @"http.+?\.pdf[\s\r\n]*";

通过包含要匹配的空格和 CRLF 的空白,使用.NetRegex.Replace 将删除整行。

Regex.Replace(data, pattern, string.Empty)

结果:

alphapdf
http://www.myurl.com/library/mydocument.doc
Gamma
于 2015-07-30T18:32:17.213 回答