Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Take out the date using Regex.

by muba (Priest)
on Jan 05, 2013 at 11:04 UTC ( #1011778=note: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    # Ditch:
    my $string = "Sat, 05 Jan 2013 04:00:15 GMT";
    $string =~ s/\d{2} [A-Z][a-z]{2} \d+ //;
    print "Take out and ditch: $string\n";
    # Output: Take out and ditch: Sat, 04:00:15 GMT
    
  2. or download this
    # Keep around:
    my $string = "Sat, 05 Jan 2013 04:00:15 GMT";
    my ($match) = $string =~ m/(\d{2} [A-Z][a-z]{2} \d+)/;
    print "Take out and keep: <$match> found in <$string>\n";
    # Output: Take out and keep: <05 Jan 2013> found in <Sat, 05 Jan 2013 
    +04:00:15 GMT>
    
  3. or download this
    # Ditch:
    my $string = "Sat, 05 Jan 2013 04:00:15 GMT";
    substr($string, 5, 12, "");
    print "Take out and ditch: $string\n";
    # Output: Take out and ditch: Sat, 04:00:15 GMT
    
  4. or download this
    # Keep around:
    my $string = "Sat, 05 Jan 2013 04:00:15 GMT";
    my $match = substr($string, 5, 11); 
    print "Take out and keep: <$match> found in <$string>\n";
    # Output: Take out and keep: <05 Jan 2013> found in <Sat, 05 Jan 2013 
    +04:00:15 GMT>
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1011778]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (20)
As of 2014-07-25 17:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (174 votes), past polls