You need to call find() on the Matcher before you can call group() and related functions: if (m.find()) { System.out.println("id = " + m.group(1)); }