Created
February 5, 2014 05:48
-
-
Save mather/8818043 to your computer and use it in GitHub Desktop.
Parser CombinatorでIPアドレスのチェック ref: http://qiita.com/mather314/items/dfa76148270f10bbad95
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
util.Try(InetAddress.getByName(str)).isSuccess |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment