# perldoc > Test::Unit::Assertion::Regexp

## NAME
    [Test::Unit::Assertion::Regexp](https://www.chedong.com/phpMan.php/perldoc/Test%3A%3AUnit%3A%3AAssertion%3A%3ARegexp/markdown) - Assertion with regex matching

## SYNOPSIS
        require [Test::Unit::Assertion::Regexp](https://www.chedong.com/phpMan.php/perldoc/Test%3A%3AUnit%3A%3AAssertion%3A%3ARegexp/markdown);

        my $assert_re =
          [Test::Unit::Assertion::Regexp](https://www.chedong.com/phpMan.php/perldoc/Test%3A%3AUnit%3A%3AAssertion%3A%3ARegexp/markdown)->new(qr/a_pattern/);

        $assert_re->do_assertion('a_string');

    This is rather more detail than the average user will need. [Test::Unit::Assertion::Regexp](https://www.chedong.com/phpMan.php/perldoc/Test%3A%3AUnit%3A%3AAssertion%3A%3ARegexp/markdown)
    objects are generated automagically by [Test::Unit::Assert::assert](https://www.chedong.com/phpMan.php/perldoc/Test%3A%3AUnit%3A%3AAssert%3A%3Aassert/markdown) when it is passed a regular
    expression as its first parameter.

        sub test_foo {
          ...
          $self->assert(qr/some_pattern/, $result);
        }

    If the assertion fails then the object throws an exception with details of the pattern and the
    string it failed to match against.

    Note that if you need to do a 'string does *not* match this pattern' type of assertion then you
    can do:

       $self->assert(qr/(?!some_pattern)/, $some_string)

    ie. Make use of the negative lookahead assertion.

## IMPLEMENTS
    [Test::Unit::Assertion::Regexp](https://www.chedong.com/phpMan.php/perldoc/Test%3A%3AUnit%3A%3AAssertion%3A%3ARegexp/markdown) implements the [Test::Unit::Assertion](https://www.chedong.com/phpMan.php/perldoc/Test%3A%3AUnit%3A%3AAssertion/markdown) interface, which means it can
    be plugged into the [Test::Unit::TestCase](https://www.chedong.com/phpMan.php/perldoc/Test%3A%3AUnit%3A%3ATestCase/markdown) and friends' "assert" method with no ill effects.

## DESCRIPTION
    The class is used by the framework to provide sensible 'automatic' reports when a match fails.
    The old:

        $self->assert(scalar($foo =~ /pattern/), "$foo didn't match /.../");

    seems rather clumsy compared to this. If the regexp assertion fails, then the user is given a
    sensible error message, with the pattern and the string that failed to match it...

## AUTHOR
    Copyright (c) 2001 Piers Cawley <<pdcawley@iterative-software.com>>.

    All rights reserved. This program is free software; you can redistribute it and/or modify it
    under the same terms as Perl itself.

## SEE ALSO
    *   [Test::Unit::TestCase](https://www.chedong.com/phpMan.php/perldoc/Test%3A%3AUnit%3A%3ATestCase/markdown)

    *   [Test::Unit::Assertion](https://www.chedong.com/phpMan.php/perldoc/Test%3A%3AUnit%3A%3AAssertion/markdown)

