[regexp] matching word, but not beetween...

Discussion in 'Perl Misc' started by maciekkus@gmail.com, Sep 1, 2006.

  1. Guest

    Hello,

    How can I use regular expressions to match:

    "this is <b>bold and big</b> and this is not bold and big"

    I would like regexp to match "bold and big" sentence but not when
    inside <b> tag.

    Any help?

    Regards
    Maciek
     
    , Sep 1, 2006
    #1
    1. Advertising

  2. Paul Lalli Guest

    Re: matching word, but not beetween...

    wrote:
    > How can I use regular expressions to match:
    >
    > "this is <b>bold and big</b> and this is not bold and big"
    >
    > I would like regexp to match "bold and big" sentence but not when
    > inside <b> tag.
    >
    > Any help?


    Take a look at
    perldoc perlre
    and search for "lookahead" and "lookbehind"

    [untested]
    m#(?<!<b>)bold and big(?!</b>)#;

    Paul Lalli
     
    Paul Lalli, Sep 1, 2006
    #2
    1. Advertising

  3. John Bokma Guest

    wrote:

    > Hello,
    >
    > How can I use regular expressions to match:
    >
    > "this is <b>bold and big</b> and this is not bold and big"
    >
    > I would like regexp to match "bold and big" sentence but not when
    > inside <b> tag.


    If you're processing HTML you might safe yourself a lot of trouble using
    modules that could handle HTML. For example, parse the HTML into a tree
    using HTML::TreeBuilder and next deleting all b elements might safe you a
    lot of trouble.

    --
    John Experienced Perl programmer: http://castleamber.com/

    Perl help, tutorials, and examples: http://johnbokma.com/perl/
     
    John Bokma, Sep 1, 2006
    #3
  4. -berlin.de Guest

    <> wrote in comp.lang.perl.misc:
    > Hello,
    >
    > How can I use regular expressions to match:
    >
    > "this is <b>bold and big</b> and this is not bold and big"
    >
    > I would like regexp to match "bold and big" sentence but not when
    > inside <b> tag.


    Take a look at the FAQ: "How can I split a [character] delimited string
    except when inside [character]?". It's about splitting, not matching
    but the problems are related.

    Anno
     
    -berlin.de, Sep 1, 2006
    #4
  5. Guest

    Re: matching word, but not beetween...

    Thanks..
    That's what I needed :)

    This worked for me:
    (?<!<b>)(bold and big)(?!<\/b>)

    Regards,
    Maciek

    Paul Lalli napisal(a):
    > wrote:
    > > How can I use regular expressions to match:
    > >
    > > "this is <b>bold and big</b> and this is not bold and big"
    > >
    > > I would like regexp to match "bold and big" sentence but not when
    > > inside <b> tag.
    > >
    > > Any help?

    >
    > Take a look at
    > perldoc perlre
    > and search for "lookahead" and "lookbehind"
    >
    > [untested]
    > m#(?<!<b>)bold and big(?!</b>)#;
    >
    > Paul Lalli
     
    , Sep 2, 2006
    #5
    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. Andrew Stewart
    Replies:
    6
    Views:
    134
    Andrew Stewart
    Dec 14, 2007
  2. Joao Silva
    Replies:
    16
    Views:
    377
    7stud --
    Aug 21, 2009
  3. Marc Bissonnette

    Pattern matching : not matching problem

    Marc Bissonnette, Jan 8, 2004, in forum: Perl Misc
    Replies:
    9
    Views:
    243
    Marc Bissonnette
    Jan 13, 2004
  4. Gerd Pohlmann

    RegExp for matching word "" or word "" ?

    Gerd Pohlmann, Feb 4, 2004, in forum: Perl Misc
    Replies:
    5
    Views:
    474
    Gunnar Hjalmarsson
    Feb 4, 2004
  5. Bobby Chamness
    Replies:
    2
    Views:
    239
    Xicheng Jia
    May 3, 2007
Loading...

Share This Page