Skip to content

Instantly share code, notes, and snippets.

@kuharan
Created March 26, 2018 20:03
Show Gist options
  • Save kuharan/3f6b8fb87bacd129fece423f6c0c4e20 to your computer and use it in GitHub Desktop.
Save kuharan/3f6b8fb87bacd129fece423f6c0c4e20 to your computer and use it in GitHub Desktop.
//double quotes test
val pattern = """(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s*(-)\s*(-)\s*(\[.+?\])\s*"(.+?)\s(.+?)\s(.+?)"\s*(\d{1,3})\s*(\d{1,10})\s*"(.+?)"\s*"(.+?)"\s*"(.+?)"""".r;
val input = """174.371.196.220 - - [07/Sep/2017:00:06:00 +0000] "GET /cs/v1/points/bal?memberId=2164699082&accountType=10 HTTP/1.1" 200 4263 "-" "Mozilla/5.0 (Windows NT 6.0; rv:34.0) Gecko/20100101 Firefox/34.0" "-"""";
val res = input match {
case pattern(ip, username1, logname2, time, requestType, requestURL, requestMethod, status, bytes, referer, userAgent, filename ) => s"IP=$ip\nUsername=$username1\nLogname=$logname2\nTime=$time\nRequestType=$requestType\nRequestURL=$requestURL\nRequestMethod=$requestMethod\nStatus=$status\nBytes=$bytes\nReferer=$referer\nUserAgent=$userAgent\nFilename=$filename"
case _ => "NONE"
}
print(res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment