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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:57:06+00:00 2026-05-31T07:57:06+00:00

Trying to create a simple regular expression that can extract numbers(between 7 – 14)

  • 0

Trying to create a simple regular expression that can extract numbers(between 7 – 14) after a keyword starting with g letter and some id, something like following :

(g)(\d{1,6})\s+(\d{7,14}\s*)+

Lets assume :

m = (/(g)(\d{1,6})\s+(\d{7,14}\s*)+/i.match("g12 327638474 83873478 2387327683 44 437643673476"))

I have results of :

#<MatchData "g23333 327638474 83873478 2387327683 " "g" "12" "2387327683 ">

But what I need as a final result , to include, 327638474, 83873478, 2387327683 and exclude 44.

For now I just getting the last number 2387327683 with not including the previous numbers

Any help here .

cheers

  • 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-05-31T07:57:07+00:00Added an answer on May 31, 2026 at 7:57 am

    Just as a FYI, here is a benchmark showing a bit faster way of accomplishing the selected answer:

    require 'ap'
    require 'benchmark'
    
    n = 100_000
    
    s = "g12 327638474 83873478 2387327683 44 437643673476"
    
    ap s.split[1..-1].select { |x| (7..14).include? x.size }.map(&:to_i)
    ap s.split[1..-1].select { |x| 7 <= x.size && x.size <= 14 }.map(&:to_i)
    
    Benchmark.bm(11) do |b|
      b.report('include?'   ) { n.times{ s.split[1..-1].select { |x| (7..14).include? x.size }.map(&:to_i)     } }
      b.report('conditional') { n.times{ s.split[1..-1].select { |x| 7 <= x.size && x.size <= 14 }.map(&:to_i) } }
    end
    
    ruby ~/Desktop/test.rb 
    [
        [0] 327638474,
        [1] 83873478,
        [2] 2387327683,
        [3] 437643673476
    ]
    [
        [0] 327638474,
        [1] 83873478,
        [2] 2387327683,
        [3] 437643673476
    ]
                     user     system      total        real
    include?     1.010000   0.000000   1.010000 (  1.011725)
    conditional  0.830000   0.000000   0.830000 (  0.825746)
    

    For speed I’ll use the conditional test. It’s a tiny bit more verbose, but is still easily read.

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

Sidebar

Related Questions

I am trying to create a regular expression with a character class that has
I am trying to create a regular expression that understands mathematical equations (>, <,
I am trying to create a simple page that enters data in to a
I'm trying to create a simple custom validator for my project, and I can't
I am trying to create a simple matcher that matches any string consisting of
Im trying to create a simple pan and zoom app using silverlight 4, but
I am trying to create a simple dialog in MFC using Visual C++. My
I'm trying to create a simple BaSH-like grammar on ANTLRv3 but haven't been able
I'm trying to create a simple toggling sidebar using jquery, where it expands and
I am trying to create a simple mouseover effect using a combination of mouseover,

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.