Reputation: 403
condition is not matching.
string1 = "k"
string2 = "k(1)"
String regex = "\\\d+";
if ((string1 +"("+regex+")").matches(string2)) {
return true;
}
Upvotes: 0
Views: 74
Reputation: 25950
You are interverting the argument. The regex must be passed in parameter of the matches
method and the method must be called on the String to be parsed :
string2.matches(string1 + "(" + regex + ")")
Upvotes: 1
Reputation: 24444
Other way round. It's s.matches(regexp)
, not regexp.matches(s)
!
You should also escape the round brackets ('(' and ')') as they have a special meaning in regular expressions. So it should be:
string2.matches(Pattern.quote(string1) + "\\(" + regex + "\\)");
Upvotes: 1