Help with regex

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sk1ds
    New Member
    • Nov 2008
    • 3

    Help with regex

    Hi all,

    sorry not a Perl user, but I have to enter a "perl pattern matching" expression into
    a monitoring tool i'm using to parse log files for certain messages.

    The perl expression I have at the moment is

    Code:
    (.*directory does not exist.*)|(ftp.lock file exists.*running.*)|(The FTP program.*is not recognised.*)
    Which I want to match the following messages in a log file

    ftp.lock file exists may already be running
    The local directory dirname does not exist
    The transferred directory dirname does not exist
    The followup directory dirname does not exist
    Specified directory does not exist or cannot be accessed

    Am I on the right lines ?

    Can I separate each pattern with brackets like I have ?

    Any help appreciated.

    Thanks
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    without knowing anything else, I'd say you are on the right track. Have you tried your regexp with your monitoring tool?

    Comment

    • sk1ds
      New Member
      • Nov 2008
      • 3

      #3
      Originally posted by KevinADC
      without knowing anything else, I'd say you are on the right track. Have you tried your regexp with your monitoring tool?
      Thanks Kevin

      yeah, tried it with the tool (this is Oracle Grid Control BTW) but it wont seem
      to work unless it is a simple, single expression like (Error-)

      Form my information, what is the difference, in Perl terms, between

      (Err1|Err2) and (Err1)|(Err2)

      Thanks

      Comment

      • KevinADC
        Recognized Expert Specialist
        • Jan 2007
        • 4092

        #4
        This should help you:

        Code:
        $_ = 'Err2';
        
        if (/(Err1|Err2)/) {
            print "First regexp: $1\n";
        }
        if (/(Err1)|(Err2)/) {
            print "Second regexp: $2\n";
        }
        The difference is that the first one captures the match in $1 only, the second one will capture the match in $1 if it matches "Err1" or $2 if it matches "Err2".

        Comment

        • sk1ds
          New Member
          • Nov 2008
          • 3

          #5
          Originally posted by KevinADC
          This should help you:

          Code:
          $_ = 'Err2';
          
          if (/(Err1|Err2)/) {
              print "First regexp: $1\n";
          }
          if (/(Err1)|(Err2)/) {
              print "Second regexp: $2\n";
          }
          The difference is that the first one captures the match in $1 only, the second one will capture the match in $1 if it matches "Err1" or $2 if it matches "Err2".
          Thanks for that Kevin - much appreciated

          Comment

          Working...