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

Perl-style regular expression

P: 2
I have'nt used perl-style regular expression much.

i have a need to search for a string called ORA-04031 error from a log file

I use the following regular expression

ORA-0*(4031)[^0-9]

and the regular expression used does not find the search string in the log file
The log file has the following contents
ORA-04031: Unable to allocate 1024 bytes of shared memory

Please provide help at the earliest
Thank you
Aug 28 '08 #1
Share this Question
Share on Google+
5 Replies


Ganon11
Expert 2.5K+
P: 3,652
If you are looking for the string ORA-04031 and ONLY that string, then tell the regex engine that:

Expand|Select|Wrap|Line Numbers
  1. $logfile =~ /ORA-04031/
0 isn't a special character in Perl regex's, and the () is for capturing some match.

If this isn't what you're trying to do, please explain your problem in more detail.
Aug 28 '08 #2

KevinADC
Expert 2.5K+
P: 4,059
The dash will need to be escaped:

Expand|Select|Wrap|Line Numbers
  1. $logfile =~ /ORA\-04031/
otherwise perl will think A-0 is a range, an invalid one, and return an error.
Aug 28 '08 #3

P: 2
Thanks for your reply.

I have need to monitor other strings along with ORA-4031 as well - such as
ORA-0600
ORA-7445
ORA-4031


Each of the string is following by text characters. That is why i was going for that kind of grouping - since i wanted to test if the first ORA-4031 works then
i was going to modify the regular expression to look for ORA- 7445 and ORA- 0600

Let me know
Thanks
Aug 28 '08 #4

Ganon11
Expert 2.5K+
P: 3,652
So you're looking for the letters ORA, followed by a - (which I forgot needed to be escaped), followed by 4 digits:

Expand|Select|Wrap|Line Numbers
  1. $logfile =~ /ORA\-\d{4}/
The \d is for a numeric character, the {4} is for 4 of the previous character class.
Aug 28 '08 #5

numberwhun
Expert Mod 2.5K+
P: 3,503
So you're looking for the letters ORA, followed by a - (which I forgot needed to be escaped), followed by 4 digits:

Expand|Select|Wrap|Line Numbers
  1. $logfile =~ /ORA\-\d{4}/
The \d is for a numeric character, the {4} is for 4 of the previous character class.
On top of what Gannon said, if the string you are looking for is always at the beginning of each line where it is found, then you can do the following:

Expand|Select|Wrap|Line Numbers
  1. $logfile =~ /^ORA\-\d{4}/
This will provide you a more minimalistic approach and possibly be a touch faster as the "^" at the beginning of the regex tells the regex engine to match from the beginning of the line.

Regards,

Jeff
Aug 29 '08 #6

Post your reply

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