I'm attempting to teach myself regex and I have a question concerning two different methods for capturing the HTTP status code (301) in the below fake apache access log. I realize that this regex would only capture the status code in this one single message, but it's just a proof of concept.
11.22.33.44 - - [17/Aug/2019:11:24:01 -0400] "GET /posts/posts/explore HTTP/1.0" 301 5024 "http://www.someurl.blah/faq.php" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_12_5) AppleWebKit/5310 (KHTML, like Gecko) Chrome/29.0.801.0 Safari/5310"
So I could do this using read ahead and look behind to make a full match:
(?<=HTTP\/1.0"\s)(301)(?=\s5024)
Or I could just capture the status code in a group:
HTTP\/1.0"\s(?<status_code>301)
I'm a total noob here, but it just seems like it would be easier to capture "in between" type strings as groups as in the second example. I'm just having a disconnect understanding why I wouldn't always just capture by group. I hope this makes sense.