You're not even using your matcher
for matching. You're using String#matches()
method. Both that method and Matcher#matches()
method matches the regex against the complete string, and not a part of it. So your regex should cover entire string. If you just want to match with a part of the string, use Matcher#find()
method.
You should use it like this:
if(matcher.find(ct.toLowerCase())) {
// Found regex pattern
}
BTW, if you only want to see if a string starts with t
, you can directly use String#startsWith()
method. No need of regex for that case. But I guess it's a general case here.