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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:35:16+00:00 2026-05-27T11:35:16+00:00

I need a regex that would validate first 4 digit set and then 3

  • 0

I need a regex that would validate first 4 digit set and then 3 digits. The first foure digits need to be identical.

Acceptable entries should be for example:

7777989  
8888767 

Invalid entries:

7778888
7777abc
8989123

Now my problem is that in my code iam creating the regexes based on class names. for example something like this

if (currentChar == 'n') regex += '[0-9]'; 
else if (currentChar == 'd') regex += '^[0-9]+$';

in above code n and d is class name where n represents “any digit” and d represents “identical digits”. So for the above example, the rule would be ddddnnn.

  • 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-27T11:35:17+00:00Added an answer on May 27, 2026 at 11:35 am
    ^(\d)\1{3}\d{3}$
    

    should do it.

    ^     # Start of string
    (\d)  # Match a single digit, capture in group 1
    \1{3} # Match the same digit as in group 1, three times
    \d{3} # Match three digits (any)
    $     # End of string
    

    A quick and dirty regex generator (in Python), assuming that all d digits have to be identical:

    def makere(rule):
        first_d = True
        parts = ["^"]
        for letter in rule:
            if letter == "d":
                if first_d:
                    parts.append(r"(\d)")
                    first_d = False
                else:
                    parts.append(r"\1")
            if letter == "n":
                parts.append(r"\d")
        parts.append("$")
        return ''.join(parts)
    

    Result:

    >>> makere("ddddnnn")
    '^(\\d)\\1\\1\\1\\d\\d\\d$'
    >>> makere("ddnnndd")
    '^(\\d)\\1\\d\\d\\d\\1\\1$'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help. I am looking for a regex that would match the
Hello I need to find regex that would get middle section of this text:
I need to have a REGEX that would filter out and only accept a
I need a Regex that will match a java method declaration. I have come
I need a regex that matches all strings ending in .cs, but if they
I need a regex that also matches Chinese, Greek, Russian, ... letters. What I
I need a regex that matches the following (the brackets indicate I want to
I need a regex that will give me the following results from each example
I need a regex that will match blahfooblah but not blahfoobarblah I want it
Given a file path such as: \\server\folder_A\folder_B\etc\more.mov I need a regex that'll give me

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.