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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:56:43+00:00 2026-06-06T12:56:43+00:00

I am very new to Regular expression so I apologise for the ‘noobyness’ of

  • 0

I am very new to Regular expression so I apologise for the ‘noobyness’ of the question…
I need to match a pattern for an ID we use at work.

So far the only specification for the pattern is that it will be 9 characters long, and comprised of Capital letters and digits. The ID can contain 1 or any number of Capital letters or digits, so long as the total length of the string is 9 characters long.

So far i have the following… [A-Z][0-9]{9}
this does not makes sure the string has atleast one letter or digit (so a 9 character long string would pass)… Alos, Im sure it matched a 9 letter word made of non capitals.

I have done a fair bit of googling, but i have not found anything dumbed down enough for me to understand.

Any help very apppreciated 🙂

Thanks

EDIT: Just to recap the requirements – The id has to be 9 characters long, no more no less. It will be comprised of capital letters and digits. There can be any amount of either letter or digit, so long as the id contains atleast one of each (so BH98T6YUO or R3DBLUEEE or 1234R6789

I will also post my code to make sure that bits not wrong… ??

 string myRegex = "A ton of different combinations that i have tried";
 Regex re = new Regex(myRegex);

        // stringCombos is a List<string> containing all my strings
        // The strings contain within them, my id
        // I am attempting to pull out this id 
        // the below is just to print out all found matches for each string in the list 
        foreach (string s in stringCombos)
        {
            MatchCollection mc = re.Matches(s);
            Console.WriteLine("-------------------------");
            Console.Write(s);
            Console.WriteLine("  ---  was split into the following:");
            foreach (Match mt in mc)
            {
                Console.WriteLine(mt.ToString());
            }
        }
  • 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-06T12:56:44+00:00Added an answer on June 6, 2026 at 12:56 pm

    You actually have to learn regular expressions as a language. The curve is kind of steep, but there are a ton of excellent tutorials for the basics. Also, you might get this in a chat situation (SO has a chat functionality) – that is how I originally learnt them…

    I think this might work for your case:

    [A-Z0-9]{1,9}
    

    According to your update, for exactly 9 elements, use:

    [A-Z0-9]{9}
    

    Note, though, that the requirement to include at least one letter and at least one digit is not expressed in this solution. An easy way to do that would be to apply a second and third match to the first one:

    [0-9]*[A-Z][0-9]*
    [A-Z]*[0-9][A-Z]*
    

    Thereby matching three times. You might be able to get this result with the fancy forward and backward reference stuff, but you cannot really capture that requirement with a regular grammar.

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

Sidebar

Related Questions

I am new to regular expression and this may be a very easy question
I'm having a very basic question about regular expressions. I am trying to match
I am very new to regular expressions, and I need some help. First I
I'm very new in regular expression and I'm trying to validate date using following
Very new to Fitnesse, I need to write a test using regular expressions to
i am very new to regular expression and trying get \ character using python
I am very new to regular expression, I did a research and got a
I'm new to regular expressions and i'm feeling this very difficult to solve: I
Very new to XSL (and XML for that matter), but I need to step
Possible Duplicate: Regular Expression for Phone Number I'm kinda new to regular expressions, so

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.