I want to match a string which starts or ends with a "test" using regex in java.
Match Start of the string:- String a = "testsample";
String pattern = "^test";
// Create a Pattern object
Pattern r = Pattern.compile(pattern);
// Now create matcher object.
Matcher m = r.matcher(a);
Match End of the string:- String a = "sampletest";
String pattern = "test$";
// Create a Pattern object
Pattern r = Pattern.compile(pattern);
// Now create matcher object.
Matcher m = r.matcher(a);
How can I combine regex for starts or ends with a given string ?