I have a regex that finds a certain pattern. This works when the text is isolated. However I want this to work while it's being surrounded by other text and somehow extract it from there. Here's the pattern that I came up with. An example would be if 9708/32/M/J/15 is the text, it would find it. But if it's awfawf9708/32/M/J/15awfafwaf it can't find it.
Pattern pattern = Pattern.compile("^\\d{4}/\\d{2}/\\w/\\w/\\d{2}$");
How do I modify this to make it work in both scenarios?