Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A regex question 1

Status
Not open for further replies.

MoshiachNow

IS-IT--Management
Joined
Feb 6, 2002
Messages
1,851
Location
IL
HI,

I have 2 strings :

08/31/2006 08:47a 745,967 creoALRT.LOGcreoALRT.LOG
12/10/2006 03:08a 219,850 creoALRT_2006_11_06_001.log

I need the below regex to match the whole string starting with "creoALRT":

$LOGALERT =~ s/.*(creoALRT.*\.log)/$1/i;

However,in the first case ,the result is "creoALRT.LOG" ....
Appreciate help


Long live king Moshiach !
 
Your regex is being too greedy. If you replace the ".*" with ".*?" (without quotes of course) it makes the .* match as few characters as possible instead of as many as possible.
 
Tony,thanks

I have tried this before:

ALERT =~ s/.*(creoALRT.*?)/$1/i;

but it still comes up with "ALERT" set as "creoALRT.LOG" ...



Long live king Moshiach !
 
It was the first .* I meant. That would give you:
[tt]
creoALRT.LOGcreoALRT.LOG
creoALRT_2006_11_06_001.log
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top