Skip to main content
 首页 » 编程设计

c#之C#如何编写正则表达式

2024年01月18日34mfryf

我的文件中包含某些数据,例如:


  /页2 0 R /类型/目录/ AcroForm
  
  / Count 1 / Kids [3 0 R] / Type / Pages
  
  /筛选器/ FlateDecode /长度84


获得此输出的正则表达式是什么。

Pages Type Catalog AcroForm Count Kids Type Pages Filter FlateDecode Length 


我想在'/'之后和第二个'/'或空格之前获取字符串。

提前致谢。

请您参考如下方法:

class Program 
{ 
    static void Main()  
    { 
        string s = @"/Pages 2 0 R/Type /Catalog/AcroForm 
/Count 1 /Kids [3 0 R]/Type /Pages 
/Filter /FlateDecode/Length 84"; 
 
        var regex = new Regex(@"[\/]([^\s^\/]*)[\s]"); 
        foreach (Match item in regex.Matches(s)) 
        { 
            Console.WriteLine(item.Groups[1].Value); 
        } 
 
    } 
} 


备注:不要使用正则表达式来解析PDF文件。