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

  • Home
  • SEARCH
  • 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 9160867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:50:21+00:00 2026-06-17T13:50:21+00:00

I got expected result with =~ but not with match . Why does match

  • 0

I got expected result with =~ but not with match. Why does match give the memory reference instead of the actual match data "foo"? And why do the references change in every run of the same statement?

s= "foo"
/(?=foo)foo/ =~ s    # => 0
/(?=foo)foo/.match s # => #<MatchData:0x2e6a490>
/(?=foo)foo/.match s # => #<MatchData:0x2e66390>
/(?=foo)foo/.match s # => #<MatchData:0x2e64310>
  • 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-17T13:50:22+00:00Added an answer on June 17, 2026 at 1:50 pm

    @theTinMan is mostly correct, the reference is the output of the object’s to_s or inspect method (IRB just calls it, and Object‘s implementation is used via inheritance if it has not been over-riden)

    The =~ method returns the match position, because that is how it is defined. A MatchData object is actually a richer object that has information on the match, such as the offset (the position), any captures, etc. In essence, you can use the returned MatchData to access the values that the $~, $1, $2, etc. variables normally hold, with a clearer interface.

    Docs for MatchData: http://apidock.com/ruby/MatchData

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So i have a .wav file. from this i got the data: as expected
I've got a huge amount of data (stored in file, but it is irrelevant
I'm working on a vbscript program and I have got and Expected Statement Error.
Am new to development.I got an error regarding the Expected a Type error.In two
I keep getting this : DeprecationWarning: integer argument expected, got float How do I
I get the following error: ActiveRecord::AssociationTypeMismatch in ContractsController#create ExchangeRate(#2183081860) expected, got HashWithIndifferentAccess(#2159586480) Params: {commit=>Create,
I've got two entities, with a logical 1:1 relation which is, however, not configured
Important The question is not What does Queryable.OfType do , it's how does the
i have spend like 2 hours on this, but i still can not find
I've created a dictionnary with Python but I've got problems with extended Ascii codes.

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.