use java style regular expression in groovy fetch and extractor info ,fucking urgly

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
System.properties.putAll( ["http.proxyHost":"10.10.224.97", "http.proxyPort":"80","http.proxyUserName":"admin", "http.proxyPassword":"admin888"] )

def url="http://detail.tmall.com/item.htm?id=8039043384&"
url="http://www.baidu.com"
html=url.toURL().text
//def matcher=( html=~ /<strong id="J_StrPrice"/ )
//println matcher


println html

String ResultString = null;
try {
    Pattern regex = Pattern.compile("<strong id=\"J_StrPrice\" >([\\s\\S]*?)</strong>");
    Matcher regexMatcher = regex.matcher(html);
    if (regexMatcher.find()) {
        ResultString = regexMatcher.group(1);
        println(ResultString)
    }
    else
    {
        println("zzzz")
    }
} catch (PatternSyntaxException ex) {
    // Syntax error in the regular expression
}

原文地址:https://www.cnblogs.com/lexus/p/2567719.html