Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8921395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:31:58+00:00 2026-06-15T06:31:58+00:00

I am coming across the MatchData#captures method in Ruby for the first time and

  • 0

I am coming across the MatchData#captures method in Ruby for the first time and wanted to ask if someone could explain it a bit more for me. The Ruby docs say:

Returns the array of captures; equivalent to mtch.to_a[1..-1].

However I am currently running a regular expression on a long string and it seems to be returning me the last item evaluated? Does this make sense?

this is the string:

431cdb7b1ad8183a1434b6d1a407731fac0ea61b8d720d733fefaa77f063df8e vidcoder [23/May/2012:01:17:16 +0000] 76.78.212.49 - B24DEA4883A9FF95 REST.GET.OBJECT accounts/6/videos/xboxcCFC/video.mp4 "GET /accounts/6/videos/xboxcCFC/video.mp4 HTTP/1.1" 206 - 2 697898511 56 56 "-" "Apple Mac OS X v10.6.8 CoreMedia v1.0.0.10K549" -

this is the regex:

line.match(%r{^.*\s+HTTP.*\s+-\s+(\d+)\s+}).captures

it returns in this case the number 2

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T06:31:59+00:00Added an answer on June 15, 2026 at 6:31 am

    Since you only specified one capturing group in your regular expression, it only returns it (as a one-element array containing the “2” string, which is not the same as returning the “2” string directly):

    line.match(%r{^.*\s+HTTP.*\s+-\s+(\d+)\s+}).captures
    => ["2"]
    

    If you try to capture more elements, your array will contains more elements, just as indicated in the documentation:

    line.match(%r{^.*\s+HTTP(.*)\s+-\s+(\d+)\s+}).captures
    => ["/1.1\" 206", "2"] 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working with MS Access for the first time and coming across a few problems
I'm coming across the square bracket [] syntax quite a bit in Ruby, but
I have been coming across these two words more often but i didn't see
I remember coming across an article on I think CodeProject quite some time ago
I remember coming across a website where I could type in some code and
I've fixed this issue before (inadvertently) and I'm coming across this again. Hopefully someone
After coming across the code golf trivia around the site it is obvious people
I'm coming across an odd issue when loading asp.net pages with IE9. Basically, I'm
I keep coming across the same type of difficulty in several places in my
I remember coming across a very minimalistic PHP CMS that targets mainly artists as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.