fork(1) download
  1. object Main extends App {
  2. val line1 = "127.0.0.1 ssl.google-analytics.com"
  3. val line2 = "#127.0.0.1 ssl.google-analytics.com"
  4. val line3 = "127.0.0.1 ssl.google-analytics.com # Comment"
  5. val line4 = "#127.0.0.1 ssl.google-analytics.com # Comment"
  6.  
  7. val lineRegex = """(^#?).*(?:127\.0\.0\.1)\s+((?!-)[A-Za-z0-9-\.]{1,63}(?<!-)\.+[A-Za-z]{2,6})\s*(#?.*)""".r
  8. val m = lineRegex.findFirstMatchIn(line2).get
  9.  
  10. println(m.group(1)) // Should be # or ""
  11. println(m.group(2)) // Should be ssl.google-analytics.com
  12. println(m.group(3)) // Should be # Comment or ""
  13. }
Success #stdin #stdout 0.38s 322432KB
stdin
Standard input is empty
stdout
#
ssl.google-analytics.com