locked
Regular Expressions RRS feed

  • Question

  • Hello

    Can anybody help me to create a regular expresion , and the code for replace the text like :

    "11/11/2014 5:16:43 PM: [10160] MSI (c) (B0:9C) [17:16:43:010]: "  from lines like :

    11/11/2014 5:16:43 PM: [10160] MSI (c) (B0:9C) [17:16:43:010]: APPCOMPAT: Compatibility mode property overrides found.
    11/11/2014 5:16:43 PM: [10160] MSI (c) (B0:9C) [17:16:43:079]: APPCOMPAT: looking for appcompat database entry with ProductCode '{E2055AB2-D1C7-4147-A384-2B4B1C04282B}'.

    The result to be :

    APPCOMPAT: Compatibility mode property overrides found.

    APPCOMPAT: looking for appcompat database entry with ProductCode '{E2055AB2-D1C7-4147-A384-2B4B1C04282B}'.

    Thanks !


    clau

    Wednesday, December 10, 2014 3:02 PM

Answers


  • string input = @"11/11/2014 5:16:43 PM: [10160] MSI (c) (B0:9C) [17:16:43:010]: APPCOMPAT: Compatibility mode property overrides found.";


    Just look for "]:"

    string output = input.Substring( input.IndexOf( "]:" )+2 ).TrimStart();

    or with regex:

    string output = Regex.Replace( input, @".*?\]:\s*", "" );

    • Proposed as answer by cedric pautet Wednesday, December 10, 2014 3:41 PM
    • Marked as answer by Clauhd Wednesday, December 10, 2014 4:37 PM
    Wednesday, December 10, 2014 3:28 PM

All replies


  • string input = @"11/11/2014 5:16:43 PM: [10160] MSI (c) (B0:9C) [17:16:43:010]: APPCOMPAT: Compatibility mode property overrides found.";


    Just look for "]:"

    string output = input.Substring( input.IndexOf( "]:" )+2 ).TrimStart();

    or with regex:

    string output = Regex.Replace( input, @".*?\]:\s*", "" );

    • Proposed as answer by cedric pautet Wednesday, December 10, 2014 3:41 PM
    • Marked as answer by Clauhd Wednesday, December 10, 2014 4:37 PM
    Wednesday, December 10, 2014 3:28 PM
  • Thanks!

    clau

    Wednesday, December 10, 2014 4:37 PM