in reply to REGEX negate XML tags

A positive match would be:
[<>/] # char that is "<", ">" or "/"

Add ^ for a negative match:

[^<>/] # char that isn't "<", ">" or "/"

In addition to your pattern being bad, your tests strings are bad (<\Comment>).

use Test::More tests => 2; $comment = '<Comment>foo bar</Comment>'; ok( $comment =~ m{<Comment>[^<>/]*</Comment>}, 'Detect no specials'); $comment = '<Comment>foo < bar</Comment>'; ok( $comment !~ m{<Comment>[^<>/]*</Comment>}, 'Detect <');
$ perl -MTest::Harness -e'runtests @ARGV' 808525.t 808525.t .. ok All tests successful. Files=1, Tests=2, 0 wallclock secs Result: PASS

Replies are listed 'Best First'.
Re^2: REGEX negate XML tags
by kcvenkat123 (Initiate) on Nov 20, 2009 at 22:58 UTC
    Thank you very much for the reply and correcting the error. It worked.