1

I'm using ruby to read a file and I need to somehow parse some data from each line and store it in an array. Two example 'lines' from the file are:

64.34.145.197 - - [03/Sep/2006:05:31:37 -0400] "GET /robots.txt HTTP/1.0" 200 56
64.34.145.197 - - [03/Sep/2006:05:31:37 -0400] "GET /manual/mod/mod_autoindex.html HTTP/1.0" 200 39134

From this I need to get /robots.txt and /manual/mod/mod_autoindex.html. Using the following simple RegEx, I've been able to extract GET /robots.txt and GET /manual/mod/mod_autoindex.html but I can't seem to shake the GET.

arr.push(/GET \S+/.match(line))

I've tried some look ahead's but i'm pretty much a RegEx n00b. Any help is greatly appreciated.

1 Answer 1

2

This should do:

arr.push(/(?<=GET )\S+/.match(line))

If the HTTP is guaranteed to follow the url you might also do this to further "frame" the match:

arr.push(/(?<=GET )\S+(?= HTTP)/.match(line))

(?<=...) and (?=...) are called positive lookarounds, btw.

Sign up to request clarification or add additional context in comments.

1 Comment

just refreshed the page to say that i found the answer...and this is what I found. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.