How to use regular expressions with TestNG?

We use regular expressions in TestNG to work with a group of test methods that are named with a certain pattern.


Testng xml file.

<?xml version = "1.0" encoding = "UTF-8"?>
<!DOCTYPE suite SYSTEM "" >
<suite name = "Tutorialspoint Test ">
   <test name = "Test Cycle">
         <class name = "TestRegularExpression" />
            <exclude name= “Payment.*”/>

All the test methods with starting name Payment will be excluded from the regression suite.


public void PaymentHistory(){
   System.out.println("Payment history validation is successful”);
public void Login(){
   System.out.println("Login is successful”);
public void PaymentDefault(){
   System.out.println("Payment default verification is successful”);

Login() will be executed, but all the methods starting with name Payment will be excluded from execution. This is achieved using regular expression(Payment.*).