Perl-style regular expression
Question posted by: prekida
(Newbie)
on
August 28th, 2008 03:06 PM
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
5
Answers Posted
If you are looking for the string ORA-04031 and ONLY that string, then tell the regex engine that:
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.
The dash will need to be escaped:
otherwise perl will think A-0 is a range, an invalid one, and return an error.
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
So you're looking for the letters ORA, followed by a - (which I forgot needed to be escaped), followed by 4 digits:
The \d is for a numeric character, the {4} is for 4 of the previous character class.
Quote:
Originally Posted by Ganon11
So you're looking for the letters ORA, followed by a - (which I forgot needed to be escaped), followed by 4 digits:
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:
- $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
|
|
|
What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 197,018 network members.
|