Home: Perl Programming Help: Regular Expressions:
Help me with this regular expression!



AsiaSkyly
Novice

Aug 15, 2011, 5:41 PM


Views: 8136
Help me with this regular expression!

Hello guys I am stuck...

I have files named:

1. PRODUCTIONSPAINMAIN_EXP_110814
2. PRODUCTIONSPAINMAIN_EXP_110814_AFK_LIST
3. PRODUCTIONUSAMAIN_EXP_110814_AFK_LIST
4. PRODUCTIONSPAINMAIN_EXP_110812
5. PRODUCTIONSPAINMAIN_TXT_110814
6. PRODUCTIONSPAINMAIN_TXT_110814_TV_LST

The date is usually yesterday's date, so I have that in a variable called $yesterday. The country is the $COUNTRY variable.

Here is my pattern match which only partially works.

$file =~ /^PRODUCTION[$COUNTRY].MAIN+.*[$yesterday]$/

Assuming $yesterday = 110814 and $COUNTRY = SPAIN

That matches: 1 and 5

I need something that matches 1,2,5 and 6.


BillKSmith
Veteran

Aug 15, 2011, 7:16 PM


Views: 8132
Re: [AsiaSkyly] Help me with this regular expression!

Remove the end-of-line anchor ($) and your regex will ignore text after $yesterday.
Good Luck,
Bill


FishMonger
Veteran / Moderator

Aug 16, 2011, 6:18 AM


Views: 8128
Re: [AsiaSkyly] Help me with this regular expression!

You also need to remove the brackets. Those brackets are defining a character class, which is not what you want.


wickedxter
User

Aug 24, 2011, 6:15 AM


Views: 7487
Re: [AsiaSkyly] Help me with this regular expression!

try that it will capture everything after the last _ and everthing after that


Code
  my $production_country = "PRODUCTION" . $country . "MAIN"; $file =~ /$production_country\_*\w*\_(.*)/ print $1;



(This post was edited by wickedxter on Aug 24, 2011, 6:15 AM)