Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Matching the author and post date of an article

by bmal (Novice)
on Dec 26, 2001 at 12:05 UTC ( [id://134363]=perlquestion: print w/replies, xml ) Need Help??

bmal has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

Is there any way to match the Author and post Date of an article, e.g., a news? Normally the content of a news begins with:

============= Title By: Author Posted: Date =============

But not always like that. When the 'by' is remove, or the 'posted' is removed, is there any way to tell whether the line is of the author's name, or the date? using regular expression?

Thanks

Edit ar0n -- fixed formatting

Replies are listed 'Best First'.
Re: Matching the author and post date of an article
by grep (Monsignor) on Dec 26, 2001 at 13:38 UTC
    Ok.. I'm going to make some assumptions, since the only variable you have given me is the 'by' or 'posted' missing from the block of text.

    Since you did not give me code, I will not give you code. Hopefully I can point you in the right direction.

    First you must establish where the data should be. This looks fairly easy since your example has only 5 lines. So keep track of where you are and what kind of data you are expecting. Then be very careful and write a regex to handle every situation you can think of.
    The nice thing about a regex here is:
    You can check the format of the data to make sure you are getting what you are expecting (if you are not getting what your are expecting then determine whether it's bad data or a bad regex).
    You can capture the data right after the regex.

    HTH

    grep
    grep> cd pub 
    grep> more beer
    
Re: Matching the author and post date of an article
by tachyon (Chancellor) on Dec 26, 2001 at 15:54 UTC
    $string = ' ============= Title By: Author Posted: Date ============='; print "Posted by: ", $1 if $string =~ m/By:\s*(\S+)\n/i; print "Date posted: ", $1 if $string =~ m/Posted:\s*(\S+)\n/i;

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: Matching the author and post date of an article
by Anonymous Monk on Dec 26, 2001 at 13:07 UTC
    yes. no need for a regex. if date line is always "Posted: Date", use perlfunc:substr. that is all.
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://134363]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (2)
As of 2024-04-26 03:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found