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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:18:32+00:00 2026-06-11T09:18:32+00:00

I get a 15-digits input string, i.e. 001230123456789 . It has two numbers –

  • 0

I get a 15-digits input string, i.e. 001230123456789.
It has two numbers – the first is 00123 (min. 1 non-zero digit, max. 5 digits), the second is 0123456789 (min. 100000000, max. 10 digits). The captured output (those numbers) should not contain leading zeros.

The easier and, probably, the only proper way to do it (in Python) is the array slicing and lstrip():

input = "001230123456789"
output = [(input[:5].lstrip('0'), input[5:].lstrip('0'))]
# ('123', '123456789')

But I have a task to do the same thing with a regular expression.

I’m stuck with having zome zeros left, whether I’ve tried greedy options or not.
I’ve ended with that one: 0{0,4}([1-9]\d{0,4})0?([1-9]\d{8,9})
and it passes 3/6 of my tests:

000010111111111 -    ('10', '111111111')     (should be ('1', '111111111'))
116402151672479 - OK ('11640', '2151672479')
006421651672479 -    ('6421', '651672479')   (should be ('642', '1651672479'))
712120751672479 - OK ('71212', '751672479')
712121551672479 - OK ('71212', '1551672479')
006400351672479 -    ('6400', '351672479')   (should be ('640', '351672479'))

Is there any way to do it with just a regex?

Full sample source code with a test and expected values on pastie.org.

  • 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-11T09:18:33+00:00Added an answer on June 11, 2026 at 9:18 am

    Here you go.

        /^0*(\d{1,5})(?<=.{5})(?<!00000)(?!00)(?=\d{10}$)0*(.+)/
          | |        |        |         |     |          | |
          | |        |        |         |     |          | capture 2nd number
          | |        |        |         |     |          |
          | |        |        |         |     |          chomp leading zeroes
          | |        |        |         |     |
          | |        |        |         |     assert there're 10 digits ahead
          | |        |        |         |
          | |        |        |         assert second part at least 100000000
          | |        |        |
          | |        |        make sure first part at least one nonzero digit
          | |        |
          | |        assert there are 5 chars behind (already tested numeric)
          | |
          | capture 1st number (don't worry; the assertions will fix this up)
          |
          chomp leading zeroes (i'm going to line up these comments damn it!)
    

    Here’s a Rubular demo.

    (The (?:^|\s) and (?:\s|$) are for presentation purposes only.)

    And here are the results:

        000010111111111             -->     1       111111111
        116402151672479             -->     11640   2151672479
        006421651672479             -->     642     1651672479
        712120751672479             -->     71212   751672479
        712121551672479             -->     71212   1551672479
        006400351672479             -->     640     351672479
    
        # not enough digits        
        71212155167247              -->     no match
    
        # too many digits          
        7121215516724798            -->     no match           
    
        # first part == 0          
        000001551672479             -->     no match            
    
        # second part < 100,000,000
        712120098765479             -->     no match
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get the single digits from two digits.for example if 36 I
How would I get last 12 digits of a string using mysql? Let's say
I want to get aspect ratio of a monitor as two digits : width
I'm getting a string from input() which consists of digits separated by spaces (1
How do I get what the digits of a number are in C++ without
I'm wondering how I can get my textbox to only accept digits and dots,
I know there are ways to get the number of digits after a decimal
I want to know how to get a 4-digit random number in Java. I
I wonder if there is a better way to get the last digit of
In Python, using calendar.timegm(), I get a 10 digit result for a unix timestamp.

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.