Extract 32 characters id from URL using regex

Viewed 35

I have the following different URLs and how to extract the 32 characters from them.

http://www.google.com/AppleStore/84c7a26fb7aa4a0495a8e89a667a68a7/watch http://www.google.com/AppleStore/84c7a26fb7aa4a0495a8e89a667a68a7/watch/series5 http://www.google.com/AppleStore/84c7a26fb7aa4a0495a8e89a667a68a7/ipad/6u890358-94qw-477b-ea9e-095fr089t60r http://www.google.com/AppleStore/84c7a26fb7aa4a0495a8e89a667a68a7/ipad

The output should be: 84c7a26fb7aa4a0495a8e89a667a68a7

This is what I have tried but it is giving me null value. Can someone help me finding the correct regex expression.

String pattern = "(?<!=)[0-9a-f]{32}"; 
Pattern compiledPattern = Pattern.compile(pattern);
Matcher matcher = compiledPattern.matcher(url);
  if (matcher.find()) {
      return matcher.group(); 
  } 
0 Answers
Related