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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:06:39+00:00 2026-05-27T17:06:39+00:00

I am newbie in ruby and regular expressions and I have this function write

  • 0

I am newbie in ruby and regular expressions and I have this function write in PHP, and I would need to rewrite it to Ruby.

function date_number_id($id_number) { 
    if (preg_match('~^([0-9]{2})([0-9]{2})([0-9]{2})/([0-9]{3,4})$~', $id_number, $match)) { 
        return (strlen($match[4]) < 4 || $match[1] >= 54 ? "19" : "20") . "$match[1]-" . sprintf("%02d", $match[2] % 50) . "-$match[3]"; 
    } 
    else
    {
      return false; 
    }
} 

Could you help me please, with it?

Many thanks!

EDIT: This is a function that prints from the identification number the birthday day. The input is for example: 890807/5089

  • 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-27T17:06:40+00:00Added an answer on May 27, 2026 at 5:06 pm

    Unless I missed something…

    def date_number_id(id_number)
      match = /^([0-9]{2})([0-9]{2})([0-9]{2})\/([0-9]{3,4})$/.match(id_number)
      if match
        return "#{match[4].to_i < 4 || match[1].to_i >= 54 ? '19' : '20'}#{match[1]}-#{sprintf("%02d", match[2].to_i % 50)}-#{match[3]}"
      else
        return false
      end
    end
    

    I think the mapping to PHP is obvious, but if there’s something you don’t understand why it is so, ask.

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

Sidebar

Related Questions

I am newbie in Ruby.. seeking some help.. I have a code DB =
Is is that I'm a newbie learning Ruby, or does it really have more
I'm a newbie ruby on rails programmer, so forgive me if this is a
I'm very newbie in ruby and need your help. I must save a Topic
I'm a newbie o thin. I have a ruby on rails application. Today I
Newbie to ruby this is my first project I am using the FasterCSV Gem
I'm a complete newbie in ruby but I can feel that this code can
WARNING: Complete newbie to RoR and Ruby alert! * I have a login method
I am a Ruby newbie and I have been struggling with the following routing
I'm a newbie to Ruby, I have a problem following the Poignant Guide to

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.