By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,773 Members | 1,710 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,773 IT Pros & Developers. It's quick & easy.

Help with regex

P: 3
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

Expand|Select|Wrap|Line Numbers
  1. (.*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
Nov 11 '08 #1
Share this Question
Share on Google+
4 Replies


KevinADC
Expert 2.5K+
P: 4,059
without knowing anything else, I'd say you are on the right track. Have you tried your regexp with your monitoring tool?
Nov 11 '08 #2

P: 3
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
Nov 11 '08 #3

KevinADC
Expert 2.5K+
P: 4,059
This should help you:

Expand|Select|Wrap|Line Numbers
  1. $_ = 'Err2';
  2.  
  3. if (/(Err1|Err2)/) {
  4.     print "First regexp: $1\n";
  5. }
  6. if (/(Err1)|(Err2)/) {
  7.     print "Second regexp: $2\n";
  8. }
  9.  
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".
Nov 11 '08 #4

P: 3
This should help you:

Expand|Select|Wrap|Line Numbers
  1. $_ = 'Err2';
  2.  
  3. if (/(Err1|Err2)/) {
  4.     print "First regexp: $1\n";
  5. }
  6. if (/(Err1)|(Err2)/) {
  7.     print "Second regexp: $2\n";
  8. }
  9.  
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
Nov 12 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.