For example, I want to find a string contains the below string.
<a href="http://www.abc.com/Cool">Cool</a>
The "Cool" can be any开发者_开发技巧 string but must the same at those 2 places.
How to use Pattern and Matcher to achieve this? Thanks!
<a href="http://www\.abc\.com/([^"]*)">\1</a>
matches the string as specified. So, in Java:
Pattern regex = Pattern.compile("<a href=\"http://www\\.abc\\.com/([^\"]*)\">\\1</a>");
Matcher regexMatcher = regex.matcher(subjectString);
foundMatch = regexMatcher.find();
Have you attempted a simple approach yet such as making a list of all unique words and then looping through each word, checking the occurrence count in the original string? The simple regex \b\w+\b matches words.
Here's an article explaining how to match consecutive duplicate words. You should be able to adapt this easily to your needs.
精彩评论