sign in | join about | help | sitemap
Connecting Tech Pros Worldwide
prekida's Avatar

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
Ganon11's Avatar
Ganon11 August 28th, 2008 04:28 PM
Moderator - 3,405 Posts
#2: Re: Perl-style regular expression

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.
KevinADC's Avatar
KevinADC August 28th, 2008 06:23 PM
Expert - 3,608 Posts
#3: Re: Perl-style regular expression

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.
prekida's Avatar
prekida August 28th, 2008 06:40 PM
Newbie - 2 Posts
#4: Re: Perl-style regular expression

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
Ganon11's Avatar
Ganon11 August 28th, 2008 09:20 PM
Moderator - 3,405 Posts
#5: Re: Perl-style regular expression

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.
numberwhun's Avatar
numberwhun August 29th, 2008 01:05 PM
Forum Leader - 2,155 Posts
#6: Re: Perl-style regular expression

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:

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
Reply
Not the answer you were looking for? Post your question . . .
197,018 members ready to help you find a solution.
Join Bytes.com

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.
Post your question now . . .
It's fast and it's free

Popular Articles

Top Perl Contributors