CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



AsiaSkyly
Novice

Aug 15, 2011, 5:41 PM

Post #1 of 4 (5197 views)
Help me with this regular expression! Can't Post

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

Post #2 of 4 (5193 views)
Re: [AsiaSkyly] Help me with this regular expression! [In reply to] Can't Post

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

Post #3 of 4 (5189 views)
Re: [AsiaSkyly] Help me with this regular expression! [In reply to] Can't Post

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

Post #4 of 4 (4548 views)
Re: [AsiaSkyly] Help me with this regular expression! [In reply to] Can't Post

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)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives