I am using a regex to extract the gold quotes from a webpage. I am parsing it to a string, then using regex to extract the quotes.
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class HelloWorld{
public static void main(String []args){
String str = "----------------------------------------------------------------------"
+ "Metals Bid Ask Change Low High "
+ "----------------------------------------------------------------------"
+ "Gold 1176.40 1177.40 -8.60 -0.73% 1171.90 1183.90";
Pattern pattern = Pattern.compile("Gold(\\s{9})(\\d{4}).(\\d{2})");
Matcher matcher = pattern.matcher(str);
if (matcher.find())
{
System.out.println(matcher.group());
}
else {
System.out.println("No string found");
}
}
}
This code finds the "Gold 1176.40" string that I want, but I can't save it as another string, as in
String temp = matcher.group();
How can I do this?