I need a help. I am writing a method which will return true if 1954 is in string images/deal/129277/1954-bonus.jpg. I can use string.contains but it won't be accurate always. Instead I want it to return true if 1954 is at exact place. Below sourceKey is images/deal/129277/1954-bonus.jpg and oldImageId is 1954.
Below code is not working.
private boolean keyMatches(String sourceKey, String oldImageId){
Pattern pattern = Pattern.compile("(.*?)/(\\d+)/(\\d+)-(.*)");
Matcher matcher = pattern.matcher(sourceKey);
return oldImageId.equals(matcher.group(3));
}