in reply to Re: regular expression and nested tags
in thread regular expression and nested tags

Just thought that starting at <div> after B would result in a better nongreedy result.

Is there a way to match a string contained between two delimiters which does not contain a given word? (not a class)

Replies are listed 'Best First'.
Re^3: regular expression and nested tags
by ikegami (Patriarch) on Jun 12, 2009 at 21:06 UTC

    No, it only affects /.*/. It doesn't affect any other part of the match, namely, the earlier /<div>/.

    Is there a way to match a string contained between two delimiters which does not contain a given word? (not a class)

    The following would do here:
    m{<div>(?:(?!</div>).)*</div>}

      That doesn't work. I must be doing something wrong:

      #!perl $a = 'A<div>B<div>C<div>D</div>E</div>F</div>G'; $a =~ m%<div>((?:(?!</div>).)*)</div>%; print "=$1=\n";

      I want to get just =D=. Also tried variations of this advanced patterns like look-behind without success.

        So exclude <div> too!