Regular Expression Help please

M

Max Adams

All,

I have this regular expression which a guy here provided yesterday, this
regexp parses an executable name from a log file, however it only works when
the executable name is part of a fully qualified name, and not when only the
executable name is specified. Here is my scenario:

The regexp will successfully parse "Stages.exe" for the first entry in the
log file, but it will not parse "Stages.exe" in the second entry.

..... [SERVER06:c:\workgroup\Stages.exe:2236: ....
..... [SERVER06:Stages.exe:2236 ....

This is the regular expression:

my @extract = ($_ =~ /.*\\([^\\]+\.exe).*SQL = ([^;]+).* [0-9]{8} ([0-9:
\/]+) .*/i);

This is a complete entry from the log file.

[SERVER05] EnumServerProceses : (0x31fdb30)
[SERVER06:c:\workgroup\Stages.exe:2588:{56DC057D-2D02-4A2A-A308-B625555C6345
}] CEnumServerProcesses::GenericExecute() : SQL = begin
PA_Stages.PR_GetProcessList:)TASKID); end; : CursonName = NULL : Options = 6
: SessionID = 12127793 11:59:29 27/08/2003 tid:1076 pid:2304
tick:16640900672768 .\EnumServerProcesses.cpp (55)

Note again that the executable path is not guarenteed to exist.

Can anyone suggest how I can modify this regexp to be independant of the
path being specified please.

PT
 
A

Anno Siegel

Max Adams said:
All,

I have this regular expression which a guy here provided yesterday, this
regexp parses an executable name from a log file, however it only works when
the executable name is part of a fully qualified name, and not when only the
executable name is specified. Here is my scenario:

Why don't you ask "the guy here"? He came up with the thing.
The regexp will successfully parse "Stages.exe" for the first entry in the
log file, but it will not parse "Stages.exe" in the second entry.

.... [SERVER06:c:\workgroup\Stages.exe:2236: ....
.... [SERVER06:Stages.exe:2236 ....

This is the regular expression:

my @extract = ($_ =~ /.*\\([^\\]+\.exe).*SQL = ([^;]+).* [0-9]{8} ([0-9:
\/]+) .*/i);

The initial ".*" in the regex does nothing, nor does the final one.
Leave them off.
This is a complete entry from the log file.

[SERVER05] EnumServerProceses : (0x31fdb30)
[SERVER06:c:\workgroup\Stages.exe:2588:{56DC057D-2D02-4A2A-A308-B625555C6345
}] CEnumServerProcesses::GenericExecute() : SQL = begin
PA_Stages.PR_GetProcessList:)TASKID); end; : CursonName = NULL : Options = 6
: SessionID = 12127793 11:59:29 27/08/2003 tid:1076 pid:2304
tick:16640900672768 .\EnumServerProcesses.cpp (55)

So how many entries are this? Where does one end and the other begin?
And why haven't you supplied one of the form that isn't matched? Please
be considerate and give us useful test data. What you provided needs
a lot of guess work.

Try this:

/:(?:.*\\)?([^\\]+\.exe).*SQL = ([^;]+).* [0-9]{8} ([0-9:\/]+) /i

Since you don't say in which ways the log data can vary, there's no
way of knowing if it will work in all cases. I'm assuming that the
first colon in a line marks the beginning of the file name.

Anno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top