You don't say whether you are processing this line by line, or need to extract your bits from a multiline lump of data. You are also not at all clear as to which parts of the lines you wish to keep, and whether you want to capture them as 2 or 3 pieces.
This assumes that you processing line by line and want 3 pieces from each line.
if( $line =~ /^([^:]+): (.+) \((\d+) minutes ago\)$/ ) {
my( $name, $text, $delay ) = ( $1, $2, $3 );
}
The regex is saying
- Capture 1 or more non-':' characters between the start of the regex and the first colon into $1.
- Then insist on, but skip, a ': '
- The capture one or more characters after that space and upto the next sequence into $2.
- Match but skip a space preceding a literal '('
followed by one or more digits (captured to $3),
followed b y the literal text ' minutes ago)',
followed by the end of line.
Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.