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()){ //обработка } 
  • You checked, these two of your matches in the text fit your mask? - Rams666
  • It goes without saying that they fit, as I said in the cycle, I get into it. - Mr_OST
  • Regex does not quite match the desired. For example: //aaaa.aa Will be found as a match. A domain will be [az] an even number of times or 3 times, not 2-4 times. Well and on trifles. - ReinRaus

1 answer 1

Problem solved. Somehow, during debugging, Matcher methods were incorrectly tested. After running without debug mode, everything worked correctly.