ฟอรัมนี้ถูกล็อกและตั้งค่าเป็นโหมดอ่านอย่างเดียวRegular Expressions

Discuss and ask questions concerning the usage of Regular Expressions (REGEXes) in the .NET Framework. 

ประกาศ

  • Link

    Regex Meets Linq

    OmegaManMVP4 กุมภาพันธ์ 2552 17:16
    If you love Regex...then Regex and Linq is a match made in Heaven. Here are two scenarios where Regex and linq can be used together.



    Here is a quick example where this input "123abcd3" will tokenized into digits or characters and placed into an IEnumerable array with values of "123", "abcd" and "3".

    The tokenization will occur and the named match Tokens will contain sub captures. Those captures will be enumerated and placed into an IEnumerable <string> array.

    string input = "123abcd3"
    string pattern = @"(?<Tokens>\d+|[a-zA-Z]+)+"
     
    var items = from Match m in Regex.Matches( input, pattern ) 
                from Capture cpt in m.Groups["Tokens"].Captures 
                select cpt.Value; 
     
     
    Console.WriteLine( string.Join( ",", items.ToArray() ) ); 
    // Outputs  
    // 123,abcd,3 





    This should get you started in using Linq with Regex. GL HTH

  • Link

    This Forum Has Been Retired

    15 ธันวาคม 2555 1:12

    This forum is locked; it is still available for review in the Archived Forums folder. Any future posts on this topic should be put in the  .NET Framework Class Libraries forum.



การกรองและการเรียงลำดับใช้ตัวเลือกเหล่านี้เพื่อจำกัดคำถามและรายการสนทนาให้แคบลง

Items 1 to 20 of 252412345ถัดไป ›Last »
 
ตอบเข้าชม
 
Items 1 to 20 of 252412345ถัดไป ›Last »