@@ -728,6 +728,50 @@ Note that the `BASH_REMATCH` array is available immediately after the
728728assertion succeeds but is fragile, i.e. prone to being overwritten as a side
729729effect of other actions.
730730
731+ ### ` refute_regex `
732+
733+ This function is similar to ` refute_equal ` but uses pattern matching instead of
734+ equality, by wrapping ` ! [[ value =~ pattern ]] ` .
735+
736+ Fail if the value (first parameter) matches the pattern (second parameter).
737+
738+ ``` bash
739+ @test ' refute_regex()' {
740+ refute_regex ' WhatsApp' ' Threema'
741+ }
742+ ```
743+
744+ On failure, the value, the pattern and the match are displayed.
745+
746+ ```
747+ @test 'refute_regex()' {
748+ refute_regex 'WhatsApp' 'What.'
749+ }
750+
751+ -- value matches regular expression --
752+ value : WhatsApp
753+ pattern : What.
754+ match : Whats
755+ case : sensitive
756+ --
757+ ```
758+
759+ If the value or pattern is longer than one line then it is displayed in
760+ * multi-line* format.
761+
762+ An error is displayed if the specified extended regular expression is invalid.
763+
764+ For description of the matching behavior, refer to the documentation of the
765+ ` =~ ` operator in the
766+ [ Bash manual ] : https://www.gnu.org/software/bash/manual/html_node/Conditional-Constructs.html.
767+
768+ Note that the ` BASH_REMATCH ` array is available immediately after the assertion
769+ fails but is fragile, i.e. prone to being overwritten as a side effect of other
770+ actions like calling ` run ` . Thus, it's good practice to avoid using
771+ ` BASH_REMATCH ` in conjunction with ` refute_regex() ` . The valuable information
772+ the array contains is the matching part of the value which is printed in the
773+ failing test log, as mentioned above.
774+
731775<!-- REFERENCES -->
732776
733777[ bats ] : https://github.com/bats-core/bats-core
0 commit comments