Developer Tools #2: Construyendo expresiones regulares con Regex101

$re = '/^(\S*).*\[(.*)\]\s"(\S*)\s(\S*)\s([^"]*)"\s(\S*)\s(\S*)\s"([^"]*)"\s"([^"]*)"$/';$str = '52.20.244.144 - - [24/Aug/2015:06:50:57 -0400] "GET /hol/contact.action?subject=Question+about+Junior+Essay+Contest&title=Susan+Harlow&webUserKeys=13900 HTTP/1.1" 200 5921 "http://holsteinusa.com/news/press_release2015.html" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.24 (KHTML, like Gecko) Chrome/19.0.1055.1 Safari/535.24"';preg_match($re, $str, $matches, PREG_OFFSET_CAPTURE, 0);Esta expresión nos devuelve como resultado cada componente del log:array(10) {[0] =>array(2) {[0] =>string(330) "52.20.244.144 - - [24/Aug/2015:06:50:57 -0400] "GET /hol/contact.action?subject=Question+about+Junior+Essay+Contest&title=Susan+Harlow&webUserKeys=13900 HTTP/1.1" 200 5921 "http://holsteinusa.com/news/press_release2015.html" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.24 (KHTML, like Gecko) Chrome/19.0.1055.1 Safari/535.24""[1] =>int(0)}[1] =>array(2) {[0] =>string(13) "52.20.244.144"[1] =>int(0)}[2] =>array(2) {[0] =>string(26) "24/Aug/2015:06:50:57 -0400"[1] =>int(19)}[3] =>array(2) {[0] =>string(3) "GET"[1] =>int(48)}[4] =>array(2) {[0] =>string(100) "/hol/contact.action?subject=Question+about+Junior+Essay+Contest&title=Susan+Harlow&webUserKeys=13900"[1] =>int(52)}[5] =>array(2) {[0] =>string(8) "HTTP/1.1"[1] =>int(153)}[6] =>array(2) {[0] =>string(3) "200"[1] =>int(163)}[7] =>array(2) {[0] =>string(4) "5921"[1] =>int(167)}[8] =>array(2) {[0] =>string(50) "http://holsteinusa.com/news/press_release2015.html"[1] =>int(173)}[9] =>array(2) {[0] =>string(103) "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.24 (KHTML, like Gecko) Chrome/19.0.1055.1 Safari/535.24"[1] =>int(226)}}

--

--

Full Stack Web Developer — adrianalonso.es

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store