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 7919393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:50:58+00:00 2026-06-03T15:50:58+00:00

Some samples inputs winning numbers: 1 winning numbers: 1,2,3,4 winning numbers: 1,23, 28, 273,

  • 0

Some samples inputs

winning numbers: 1
winning numbers: 1,2,3,4
winning numbers: 1,23, 28,   273, 191

Desired matches

[1]
[1,2,3,4]
[1,23,28,273,191]

It is a simple pattern, but I’m not really sure how to match all of the numbers. I was thinking something like “get the first number, then zero or more numbers preceded by a comma and possibly spaces”

winning numbers:\s*(\d+)\s*(,\s*(\d+))*

But it only matches the first one (as expected), and the last number.

I’m using ruby, so I want to be able to retrieve all of the matches in an array and pass it off. With my current regex, it matches the last number, but it also matches the comma as well cause it’s inside the parentheses.

Is my logic flawed? Or am I not expressing it as a regex correctly?
I’m using rubular to test my regex.

  • 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-03T15:51:01+00:00Added an answer on June 3, 2026 at 3:51 pm

    You can use scan method to match all numbers and then map them into the array with converting each one to integer using to_i

    numbers = "1,23, 28,   273, 191"
    
    numbers.scan(/\d+/).map(&:to_i)
     => [1, 23, 28, 273, 191]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was building a simple carousel list for learning purpose. In some carousel samples,
I'm having some trouble saving multiple entries in CakePHP. I'm not sure whether saveAll()
I've seen some samples of using 'T' to make a method reuseable for generic
I wrote an app in C++, and downloaded some samples code from the internet
I'm starting with Ruby, and while making some test samples, I've stumbled against an
Can you point me to some tutorial or samples on how I can log
I have a problem wherein I get an AmbiguousMatchException in some of the samples
I'm fiddling with a bit of c++/opencv. I was looking some of the samples
I need some asp.net pagination code samples. I would like suggestions on open source
I was playing around with some Chrome Extensions, testing stuff, changing samples, etc, when

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.