sulfericacid
Programmer
This is similar to my last post but I've spent the night fiddling and have different questions/better way to explain the question I had earlier.
Test print:
aaron: hi there everyone!! (1 second ago) (<br> in HTML)
someone else: I am writing this as a test (23 seconds ago)(br)
screw up user: I will type () and mess you up! (40 minutes ago) (br)
perhaps me: will I screw you up?
(1 hour ago)
question 1) I need to change /([^:]+): (.+) \((\d+) minutes ago\)/; because 'minutes ago' can say 'seconds ago', 'minute ago', 'day ago' or 'days ago'. I read yesterday in a regex tutorial to do something like that you'd add it in brackets like [seconds ago|minute ago|minutes ago|..] but I can't figure out how to implement it.
question 2) That same regex above WILL fail if the message (after the username and after the colon) contains one or two parenthesis. How can I make it so it'll ignore those and only worry about the ones which contain ( ## $interval ago) ?
question 3) Last but not least, I can't rip apart the string as I expected to using:
/([^:]+): (.+) \((\d+) minutes ago\)/;
my( $name, $text, $delay ) = ( $1, $2, $3 );
print "NAME:$name\nText:$text\nDelay:$delay\n\n";
}
I am trying to parse each line so I can get their username (anything before the first colon) into $name, anything after the colon but before the (## $interval ago) into $text and delay to be (## $interval ago) itself.
I know this is probably asking for a lot, but maybe not. If any of you are good at regexs, do you think you could give me a hand?
Thank you so much!
My script is below:
use strict;
use CGI qw/:standard/;
use HTML::Tree;
use LWP::Simple;
print header, start_html('test printing');
my $funky = "
my $content = get($funky);
my $tree = HTML::Tree->new();
$tree->parse($content);
# retrieve the text and split into lines
my @lines = split "<br>", $tree->as_text;
local $/;
my @good_lines;
my $good_lines;
for my $lines (@lines) {
$lines =~ s/\)/\)<br>/g;
while($lines =~ m/Next Chatter \>(.*?)\< Previous Chatter/gs){
$good_lines = $1;
push @good_lines,$good_lines;
}
foreach (@good_lines){
my @lines = split /<br>/;
foreach (@lines){
next unless $_;
/([^:]+): (.+) \((\d+) minutes ago\)/;
my( $name, $text, $delay ) = ( $1, $2, $3 );
print "NAME:$name\nText:$text\nDelay:$delay\n\n";
}
}
}
"Age is nothing more than an inaccurate number bestowed upon each of us at birth as just another means for others to judge and classify us- sulfericacid
Test print:
aaron: hi there everyone!! (1 second ago) (<br> in HTML)
someone else: I am writing this as a test (23 seconds ago)(br)
screw up user: I will type () and mess you up! (40 minutes ago) (br)
perhaps me: will I screw you up?
question 1) I need to change /([^:]+): (.+) \((\d+) minutes ago\)/; because 'minutes ago' can say 'seconds ago', 'minute ago', 'day ago' or 'days ago'. I read yesterday in a regex tutorial to do something like that you'd add it in brackets like [seconds ago|minute ago|minutes ago|..] but I can't figure out how to implement it.
question 2) That same regex above WILL fail if the message (after the username and after the colon) contains one or two parenthesis. How can I make it so it'll ignore those and only worry about the ones which contain ( ## $interval ago) ?
question 3) Last but not least, I can't rip apart the string as I expected to using:
/([^:]+): (.+) \((\d+) minutes ago\)/;
my( $name, $text, $delay ) = ( $1, $2, $3 );
print "NAME:$name\nText:$text\nDelay:$delay\n\n";
}
I am trying to parse each line so I can get their username (anything before the first colon) into $name, anything after the colon but before the (## $interval ago) into $text and delay to be (## $interval ago) itself.
I know this is probably asking for a lot, but maybe not. If any of you are good at regexs, do you think you could give me a hand?
Thank you so much!
My script is below:
use strict;
use CGI qw/:standard/;
use HTML::Tree;
use LWP::Simple;
print header, start_html('test printing');
my $funky = "
my $content = get($funky);
my $tree = HTML::Tree->new();
$tree->parse($content);
# retrieve the text and split into lines
my @lines = split "<br>", $tree->as_text;
local $/;
my @good_lines;
my $good_lines;
for my $lines (@lines) {
$lines =~ s/\)/\)<br>/g;
while($lines =~ m/Next Chatter \>(.*?)\< Previous Chatter/gs){
$good_lines = $1;
push @good_lines,$good_lines;
}
foreach (@good_lines){
my @lines = split /<br>/;
foreach (@lines){
next unless $_;
/([^:]+): (.+) \((\d+) minutes ago\)/;
my( $name, $text, $delay ) = ( $1, $2, $3 );
print "NAME:$name\nText:$text\nDelay:$delay\n\n";
}
}
}
"Age is nothing more than an inaccurate number bestowed upon each of us at birth as just another means for others to judge and classify us- sulfericacid