There is a pattern to search for url in the text. Because There may be several Matcher.find() using Matcher.find() . However, after switching to the loop body, upon exiting any Matcher method, I get an exception: java.lang.IllegalStateException: No match found . Although there are exactly 2 matches in the verification text. If we do Matcher.reset() in the body, then the behavior is even Matcher.reset() : after each command, even if it is creating a string, it is as if find () is invoked.
What could be the problem, or maybe I do not understand the mechanics of the Matcher methods?
Code example:
Pattern urlPattern = Pattern.compile("((https?|ftp|telnet)?://)?([a-zA-Z0-9-]{1,128}\\.)+([a-zA-Z]{2,4})+(:[0-9]{0,5})?(/[a-zA-Z0-9.,_@%&?+=\\~/#-]*)?"); Matcher urlMatcher = urlPattern.matcher(newText.toString()); while(urlMatcher.find()){ //обработка }
[az]an even number of times or 3 times, not 2-4 times. Well and on trifles. - ReinRaus