Groovy web console

subscribe to the feed Subscribe
to this
site

msedge extract URL for stable release x64 example

Published 4 months ago by John Ward with tags msedge stable
Actions Execute script  ▶ Edit in console Back to console Show/hide line numbers View recent scripts
import java.util.regex.Pattern
import java.util.regex.Matcher
String str = "<a href=\"https://msedgedriver.azureedge.net/104.0.1293.54/edgedriver_win32.zip\" aria-label=\"x86 stable channel, version 104.0.1293.54\">x86</a> <span class=\"separator\" aria-hidden=\"true\">| </span> <a href=\"https://msedgedriver.azureedge.net/104.0.1293.54/edgedriver_win64.zip\" aria-label=\"x64 stable channel, version 104.0.1293.54\">x64</a> <span class=\"separator\" aria-hidden=\"true\">| </span>  <a href=\"https://msedgedriver.azureedge.net/105.0.1336.2/edgedriver_win64.zip\" aria-label=\"x64 dev channel, version 105.0.1336.2\">x64</a>";

Pattern regex = Pattern.compile("<a\\s*href=[\"']([^'\"]+?)[\"'][^>]*?>\\s*x64\\s*</a>", Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE);
Matcher regexMatcher = regex.matcher(str);
//find first match and report
if(regexMatcher.find()){
    System.out.println(regexMatcher.group(1));     
}