Pattern matching [newbie]

Discussion in 'Perl Misc' started by vivek_12315, Feb 13, 2013.

  1. vivek_12315

    vivek_12315 Guest

    I m working on my perl regex code, where I have to parse a html line like :

    <a href="/question?id=15422849"><p>MY text here 1</p><p>MY text here 2</p><p>MY text here 3</p></a>

    I am doing something like:
    $string =~ m/(.*)href(.*)/;

    But this is not helping me in what I want. I want something closer to following text:

    "MY text here 1 MY text here 2 MY text here 3"

    Can some give some ideas ?
     
    vivek_12315, Feb 13, 2013
    #1
    1. Advertising

  2. vivek_12315 <> wrote:
    >I m working on my perl regex code, where I have to parse a html line like :
    >
    > <a href="/question?id=15422849"><p>MY text here 1</p><p>MY text here 2</p><p>MY text here 3</p></a>
    >
    >I am doing something like:
    >$string =~ m/(.*)href(.*)/;
    >
    >But this is not helping me in what I want. I want something closer to following text:
    >"MY text here 1 MY text here 2 MY text here 3"
    >
    >Can some give some ideas ?


    Your Question used to be Asked Frequently. Please see

    perldoc -q "remove html"

    jue
     
    Jürgen Exner, Feb 13, 2013
    #2
    1. Advertising

  3. vivek_12315

    brian d foy Guest

    In article <>,
    vivek_12315 <> wrote:

    > I m working on my perl regex code, where I have to parse a html line like :
    >
    > <a href="/question?id=15422849"><p>MY text here 1</p><p>MY text here
    > 2</p><p>MY text here 3</p></a>
    >
    > I am doing something like:
    > $string =~ m/(.*)href(.*)/;
    >
    > But this is not helping me in what I want. I want something closer to
    > following text:
    >
    > "MY text here 1 MY text here 2 MY text here 3"



    http://search.cpan.org/dist/HTML-Strip/Strip.pm
     
    brian d foy, Feb 13, 2013
    #3
  4. Henry Law <> wrote:
    >On 13/02/13 00:16, vivek_12315 wrote:
    >> I m working on my perl regex code, where I have to parse a html line like :
    >>
    >> <a href="/question?id=15422849"><p>MY text here 1</p><p>MY text here 2</p><p>MY text here 3</p></a>

    >
    >I appreciate that you call yourself a newbie, and to you what I'm about
    >to suggest may seem complicated and difficult; but that's the way we all
    >learn ...
    >
    >Have you thought of parsing the HTML properly, using a module like
    >HTML::Tree or HTML::TreeBuilder? The hardest part is choosing the
    >module; after that you should find it moderately easy to use it do what
    >you want, since it's pretty simple. And once you've done it it will
    >probably be a lot better than hand-cranked parsing code.
    >
    >Note to all concerned: I'm not joining in the "you can't parse HTML with
    >regexes" thread. In this case, at least, I'm sure that's perfectly
    >possible.


    Actually for this particular example it is almost trivial(*):
    s/<.*?>//g;
    Of course this is going to fail as soon as the HTML code becomes a tiny
    bit more complex.

    *: almost because it doesn't add the space characters between the
    individual paragraph elements.

    jue
     
    Jürgen Exner, Feb 13, 2013
    #4
    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. DelphiDude
    Replies:
    3
    Views:
    1,169
  2. Marc Bissonnette

    Pattern matching : not matching problem

    Marc Bissonnette, Jan 8, 2004, in forum: Perl Misc
    Replies:
    9
    Views:
    238
    Marc Bissonnette
    Jan 13, 2004
  3. Vandana

    Perl Pattern Matching-- Newbie

    Vandana, Jan 19, 2004, in forum: Perl Misc
    Replies:
    4
    Views:
    106
    Tad McClellan
    Jan 19, 2004
  4. Madhusudan Singh

    Newbie needs help on pattern matching

    Madhusudan Singh, Sep 2, 2004, in forum: Perl Misc
    Replies:
    7
    Views:
    129
    William Park
    Sep 3, 2004
  5. Bobby Chamness
    Replies:
    2
    Views:
    234
    Xicheng Jia
    May 3, 2007
Loading...

Share This Page