Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

I'm not quite sure what you mean by "take out" - is that a "take out and ditch", or a "take out and keep around for later use"?

# 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
# 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>

Update: come to think of it, there's always more than one way to do it, and in this case regexes aren't even needed. The same result is as easily (and much more efficiently) achieved using substr:

# 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
# 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>

In reply to Re: Take out the date using Regex. by muba
in thread Take out the date using Regex. by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (2)
    As of 2014-07-10 03:20 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      When choosing user names for websites, I prefer to use:








      Results (198 votes), past polls