// Collection of code snippets by Arne VajhÃ¸j 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.util.regex.*;

public class HostsRegex {
    public static void find(String s) {
        Pattern p = Pattern.compile("(?:^\\s*)(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})(?:\\s+)([^#]+)");
        Matcher m = p.matcher(s);
        while (m.find()) {
            System.out.println(m.group(1) + " = " + m.group(2));
        }

    }
    public static void main(String[] args) {
        find("#      102.54.94.97    rhino.acme.com          # kildeserver");
        find("#      38.25.63.10    x.acme.com              # x-klientvært");
        find("127.0.0.1      localhost");
        find("    127.0.0.2      localhost # hvad så der?");
        find("            127.0.0.3      localhost  # test");
    }
}
