import java.io.*; import java.util.*; import java.util.regex.*; class Cat { public static void main(String[] args) throws FileNotFoundException { // pattern I expect: ^\s*(\w+)\s+(-{0,1}\d+)\s*$ Pattern p = Pattern.compile("^\\s*(\\w+)\\s+(-{0,1}\\d+)\\s*$"); Scanner maggie = new Scanner( new File( args[0] )); while (maggie.hasNextLine()) { String line = maggie.nextLine(); Matcher m = p.matcher( line ); if (m.find()) { System.out.println( "Good line: " + line); String name = m.group(1); String score = m.group(2); System.out.println(" Name is: (" + name + ")"); System.out.println(" Score is: (" + score + ")"); } else { System.out.println( "Bogus line: " + line); } // System.out.println( line ); } } }