Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6968507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:27:38+00:00 2026-05-27T16:27:38+00:00

i am creating a Log Parser whereby i Load a log file and Parse

  • 0

i am creating a Log Parser whereby i Load a log file and Parse it by going through the log file one line at a time. I am using Regular Expression to parse my Files for a specific Pattern. The problem i am having is that in the actual log file there is a tab or space before or in front of the selected line and my data will not match my comparison data.

How do i remove the Tab or white space in front of the line. I tried Trim() and trimStart() that did not work. Here is my sample codes:

Log File Sample pattern:
[ANY__MOD,80,*AUDIT_GROUPS*] [ANY__MOD] audit_groups_category Key1 contains invalid value. Replace dictionary dat file with one having valid Key1 value ANY_MOD.

Regex Pattern i have for this:
string Pattern = @”/.[([.\d\s\w*]),([.\d\s\w*]),([.\d\s\w*])]\s*[([.\d\s\w*])]\s(.)*”;

Problem i am having:”\t[.22.12.,81,*AUDIT_GROUPS*] [.22.12.] audit_groups_category Key1 contains invalid value. Replace dictionary dat file with one having valid Key1 value ANY_MOD.

 [.22.12.,81,*AUDIT_GROUPS*] [.22.12.] audit_groups_category Key1 contains invalid value. Replace dictionary dat file with one having valid Key1 value ANY_MOD.

My Sample Code:

private void ValidateUsingRegularExpression(string Pattern,  string serviceName)
       {
           System.Diagnostics.Debugger.Launch();

           string line;
           int counter = 0;
           string ServiceName = Helpers.GetServiceName(serviceName, _integrationType);
           string serviceLogPath = Helpers.GetTppInstallDir() + "logs\\" + ServiceName + ".txt";
         //  string serviceLogPath = @"C:\totalpayment\logs\EngineService.txt";
         // If file does not exist
            if(!File.Exists(serviceLogPath))
           {
            throw new ApplicationException("Was unable to find Log file " + serviceLogPath );
           }

          System.IO.StreamReader file = new System.IO.StreamReader(serviceLogPath);

           line = file.ReadLine();

           while (line != null)
           {
               line = file.ReadLine();
               if (line == null)
               {
                   return;
               }
               line = line.Trim();

                   if (Regex.IsMatch(line, Pattern, RegexOptions.IgnoreCase))
                   {
                       line = line.Trim();
                       line = line.TrimStart();
                       if (ErrorToValidate == line)
                       {
                           _ValidateErrorinLogFile = "Found";
                           counter = counter + 1;
                          // counter++;
                           _TotalLinesFound = counter.ToString();
                       }

                   }
           }
       }

main function that calls

public void  ValidateCompareExclusionErrorsInLogFile()
       {

          // string Pattern = @"\[\d+\,[A-Z_]+\]
          // string Pattern = @"\[([\w\*]+),(\d+),([\w\*]+)\]\s*\[([\w\*_]+)\]\s*([\w\\d\s\.]*)";
           //string Pattern = \[([\w\*]+),(\d+),([\w\*]+)\]\s*\[([\w\*\_]+)\]\s*([\w\\d\s\.]*);

           string Pattern = @"/.*\[([.\d\s\w\*]*),([.\d\s\w\*]*),([.\d\s\\w\*]*)\]\s*\[([.\d\s\w\*]*)\]\s*(.)*";

           //ValidateUsingRegularExpression(Pattern, "TPP.EngineService");
           ValidateUsingRegularExpression(Pattern, "engine");
           ValidateUsingString(ErrorToValidate, "engine");
           //These options are here when needed,  If you need to setup different suite of test to run same scenario on different engine, 
           //this can be dynamically done by turning on the following options below. 
            //  ValidateUsingString("field","engine");

       }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T16:27:38+00:00Added an answer on May 27, 2026 at 4:27 pm

    This works with the data you provided:

    ^\s+\[[^]]+]\s*\[[^]]+\].+$
    

    And this is what that means:

    ^ (anchor to start of string)
    Any whitespace character 
    + (one or more times)
    [
    Any character not in "]"
    + (one or more times)
    ]
    Any whitespace character 
    * (zero or more times)
    [
    Any character not in "]"
    + (one or more times)
    ]
    . (any character)
    + (one or more times)
    $ (anchor to end of string)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating an import script using Nokogiri to parse an XML file and then
my friend and I are creating a log parser for a series of games.
I am creating a site and I'm using sessions to manage the user log
I'm creating a program that parses a log file for a user's name and
HI All I am creating a log file for our website which will log
In my application i am creating log file of size 5kb .If i exceeds
I'm creating a log function that will log my errors in a file. I
Can someone help me out with creating a regex expression in PHP to parse
I've seen a few questions here and there about creating event log sources using
I'm creating Unix bash script that parses web-server log file and inserts this data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.