import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "gamers_online.*\\s*(\\d+),?(\\d+),?(\\d+)";
final String string = "[...]\n\n"
+ "<div id=\"about_header_area\" class=\" global\">\n"
+ " <div class=\"about_area_inner_wrapper\">\n"
+ " <div id=\"about_monitor_video\">\n"
+ " <video width=\"100%\" height=\"auto\" autoplay muted loop playsinline poster=\"https://cdn.fastly.steamstatic.com/store/about/videos/about_hero_loop_web.png\">\n"
+ " <source src=\"https://cdn.fastly.steamstatic.com/store/about/videos/about_hero_loop_web.webm\" type=\"video/webm\">\n"
+ " <source src=\"https://cdn.fastly.steamstatic.com/store/about/videos/about_hero_loop_web.mp4\" type=\"video/mp4\">\n"
+ " </video>\n"
+ " <div id=\"about_monitor_video_gradient\"></div>\n"
+ " </div>\n"
+ " <div id=\"about_header\">\n"
+ " <div id=\"about_greeting\">\n"
+ " <div class=\"about_greeting_header\">\n"
+ " <div class=\"steam_logo\"><img src=\"https://cdn.fastly.steamstatic.com/store//about/logo_steam.svg\" alt=\"The logo for Steam\"></div>\n"
+ " <div class=\"about_subtitle\">Steam is the ultimate destination for playing, discussing, and creating games.</div>\n"
+ " <div class=\"online_stats\">\n"
+ " <div class=\"online_stat\">\n"
+ " <div class=\"online_stat_label gamers_online\">online</div>\n"
+ " 36,426,658 </div>\n"
+ " <div class=\"online_stat\">\n"
+ " <div class=\"online_stat_label gamers_in_game\">playing now</div>\n"
+ " 10,289,777 </div>\n"
+ " </div>\n"
+ " </div>\n"
+ " \n"
+ " \n"
+ " <div class=\"about_install_wrapper\">\n"
+ " <div class=\"about_install win \">\n"
+ " <a href=\"https://cdn.fastly.steamstatic.com/client/installer/SteamSetup.exe\" class=\"about_install_steam_link\">Install Steam</a>\n"
+ " </div>\n"
+ " <div class=\"installer_list\">\n"
+ " <div class=\"available_platforms\">\n"
+ " Also available on:\n"
+ " </div>\n\n"
+ " <a class=\"platform_icon\" href=\"https://cdn.fastly.steamstatic.com/client/installer/steam.dmg\">\n"
+ " <img src=\"https://cdn.fastly.steamstatic.com/store/about/icon-macos.svg\">\n"
+ " </a>\n"
+ " <a class=\"platform_icon\" href=\"https://cdn.fastly.steamstatic.com/client/installer/steam.deb\">\n"
+ " <img src=\"https://cdn.fastly.steamstatic.com/store/about/icon-steamos.svg\">\n"
+ " </a>\n"
+ " <a class=\"platform_icon\" href=\"https://support.google.com/chromebook?p=steam_on_chromebook\">\n"
+ " <img src=\"https://cdn.fastly.steamstatic.com/store/about/icon-chromeos.svg\">\n"
+ " </a>\n"
+ " </div>\n"
+ " </div>\n"
+ " </div>\n"
+ " </div>\n"
+ " </div>\n"
+ " <div class=\"learn_more_btn\">\n"
+ " <a href=\"#about_games_cta_area\" class=\"smooth_scroll\">\n"
+ " Learn more <span class=\"down_arrow\"></span>\n"
+ " </a>\n"
+ " </div>\n"
+ "</div>\n";
final Pattern pattern = Pattern.compile(regex);
final Matcher matcher = pattern.matcher(string);
if (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html