Skip to content

Instantly share code, notes, and snippets.

@mather
Created February 5, 2014 05:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mather/8818043 to your computer and use it in GitHub Desktop.
Save mather/8818043 to your computer and use it in GitHub Desktop.
Parser CombinatorでIPアドレスのチェック ref: http://qiita.com/mather314/items/dfa76148270f10bbad95
import java.net.{InetAddress,UnknownHostException}
import util.parsing.combinator.RegexParsers
object IpParsers extends RegexParsers {
def ipAddress: Parser[String] = """[0-9a-fA-F:\.]+""".r.withFilter { str =>
try {
val addr = InetAddress.getByName(str)
true
} catch {
case e: UnknownHostException => false
}
}
}
util.Try(InetAddress.getByName(str)).isSuccess
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment