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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:15:51+00:00 2026-06-05T22:15:51+00:00

The pattern i am trying to match is some characters(letters+digits+hyphens (-) ) then 5

  • 0

The pattern i am trying to match is some characters(letters+digits+hyphens(-)) then 5 digits and then 9 digits. Each part of the pattern is separated by hyphen(-) The 5-digit and 9-digit parts are optional meaning that one of them might be present while other might not be or may be both are present or may be both are absent. So the patterns can be like this

bla-12-bla-98-bla-12345-123456789     all parts(characters+5-digit+9-digit)
bla-bla-123-12345                     9-digit part absent
blasd-123456789                       5-digit part absent
no-1045-numeric-bla-bla               both numeric parts absent

The regex i came up with is this

.+(\d{5})?-?(\d{9})?$

The reasoning for above goes like this. Since the .+ in the beginning matches all characters,the (\d{5})? says that there might be 0 or 1 instance of the 5-digit part thus making it optional.

For -?, if both numeric parts are not present then there woudnt be any - but if both numeric parts are present then there would be 1 - so again i make it optional.

Similarly for (\d{9})?.

But the above pattern does not match anything. I am using python so both group(1) and group(2) return None.

Whats wrong with the above?

  • 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-05T22:15:52+00:00Added an answer on June 5, 2026 at 10:15 pm

    The problem is the .+ at the beginning. The Regex interpreter is not able to deduce when .+ is supposed to end. So your pattern does in fact match, but your match groups will always be None as you already observed. If you just use

    (\d{5})?\-?(\d{9})?$
    

    instead, it will still match all of your examples, and your match groups will be recognized properly.

    • 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 match for this pattern: /page/some/thing/is/written/here where /page is
I am trying to use regular expressions to match some text. The following pattern
I'm trying to use a regex to match a pattern such as (letter(letter|number))* ,
I'm trying to pattern match against a few types that I care about for
I'm using PHP. I'm trying to get a Regex pattern to match everything between
I'm trying to match the following: A pattern begins with /* and ends with
For some reason I am unable to get the pattern match for preference_network_ followed
I'm using Oracle regural expressions and I want to match some string, then something
I'm trying to match cases with regular expression to search and replace some text
I am trying to match <input> of type hidden fields using this pattern: /<input

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.