Quick perl question 2

Discussion in 'Perl' started by jack, Aug 25, 2003.

  1. jack

    jack Guest

    I don't want to pester, but i have just one more follow up to this script
    I'm writing:

    The files I'm pulling has bylines in them. If I do this:

    ($byline, $title) = $_ =~ /By\s?(.*)<br><br>([A-Za-z
    ]+)<br><br>.*$/;
    #($firstgraph) = $_ =~ /<p>(.*)<br><br>([A-Za-z ]+)<br><br>.*$/;
    print "By: $byline\n\n";
    print "Title: $title\n";

    Then it will print out the Byline and title. Bingo, no problem. But, If I do
    this:

    $_ =~ s/By.*<br><br>.*<br><br>/g;

    It will erase everthing up UNTIL the last two <br> tags -- which eliminates
    the whole story except the last paragraph! How do I tell to only go through
    the first and second sets of <br> tags?
    (FYI, i'm trying to remove the byline and title so I can do nifty things,
    like print out the first paragraph on an index page and correctly format the
    byline later.
    jack, Aug 25, 2003
    #1
    1. Advertising

  2. jack

    dw Guest

    "jack" <> wrote in message news:BB6E997A.373%...
    > I don't want to pester, but i have just one more follow up to this script
    > I'm writing:
    >
    > The files I'm pulling has bylines in them. If I do this:
    >
    > ($byline, $title) = $_ =~ /By\s?(.*)<br><br>([A-Za-z
    > ]+)<br><br>.*$/;
    > #($firstgraph) = $_ =~ /<p>(.*)<br><br>([A-Za-z ]+)<br><br>.*$/;
    > print "By: $byline\n\n";
    > print "Title: $title\n";
    >
    > Then it will print out the Byline and title. Bingo, no problem. But, If I

    do
    > this:
    >
    > $_ =~ s/By.*<br><br>.*<br><br>/g;
    >
    > It will erase everthing up UNTIL the last two <br> tags -- which

    eliminates
    > the whole story except the last paragraph! How do I tell to only go

    through
    > the first and second sets of <br> tags?
    > (FYI, i'm trying to remove the byline and title so I can do nifty things,
    > like print out the first paragraph on an index page and correctly format

    the
    > byline later.
    >


    Tell the .* not to be greedy by adding a ?
    $_ =~ s/By.*?<br><br>.*?<br><br>/g;

    However, this reg exp is incomplete since you don't specify what the found
    text should be replaced with....
    And, I'm not quite sure why you have the /g on there either.
    dw, Aug 25, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eric J. Roode
    Replies:
    0
    Views:
    954
    Eric J. Roode
    Jul 19, 2003
  2. =?Utf-8?B?UnlhbiBTbWl0aA==?=

    Quick Question - Newby Question

    =?Utf-8?B?UnlhbiBTbWl0aA==?=, Feb 14, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    627
    Iain Norman
    Feb 16, 2005
  3. JKop
    Replies:
    11
    Views:
    846
  4. Jürgen Exner

    Re: Quick perl script-regex question

    Jürgen Exner, Nov 4, 2011, in forum: Perl
    Replies:
    0
    Views:
    1,946
    Jürgen Exner
    Nov 4, 2011
  5. MDS

    Quick Perl question

    MDS, Oct 20, 2003, in forum: Perl Misc
    Replies:
    7
    Views:
    100
    Roy Johnson
    Oct 23, 2003
Loading...

Share This Page