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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:20:13+00:00 2026-06-11T11:20:13+00:00

I require a regex that will text that a string starts with one chaecter

  • 0

I require a regex that will text that a string starts with one chaecter (a-z) and is followed by at least one digit.

I have tried…

^[a-zA-Z]{1}\d+

my test data is…

a1234 (pass)
B123444434 (pass)
Z098745 (pass)
ZZ12345 (fail)
G4b553b3 (fail)

The problem is that the last two lines shoudl fail but dont, Im not sure if the problem is my regex or my c# (below);

    int pass = 0;
    int fail = 0;

    string[] testdata = 
    {
        "a1234", 
        "B1234", 
        "Z098745", 
        "ZZ12345", 
        "G4b5533", 
    };

    string sPattern = "[a-zA-Z]{1}\\d+";

    foreach (string s in testdata)
    {
        if (System.Text.RegularExpressions.Regex.IsMatch(s, sPattern))
        {
            pass++;
        }
        else
        {
            fail++;
        }
    }
  • 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-11T11:20:14+00:00Added an answer on June 11, 2026 at 11:20 am

    You seem to have missed ^ in your code, so Z12345 matches for ZZ12345 and b5533 matches for G4b5533.

    And as it was mentioned, {1} is redundant.

    I believe you should have

    string sPattern = "^[a-zA-Z]\\d+$";
    

    in your code.

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

Sidebar

Related Questions

I have the following string that would require me to parse it via Regex
I need a Regex that will match a java method declaration. I have come
I am trying to write a regex that will allow me to parse CSV
I'm writing a small web app that will receive and parse tab-delimited text files
Ok I need a one line php-ready regex that encompasses a number of keywords,
I'm looking for a routine that will format a string of numbers as a
I have a form text field that has a KeyUp event. On KeyUp I'm
I'm trying to write a search and replace regex that will detect whether HTML
I need a regex that will determine if a given SQL statement has a
I have to write a program that will go through a given folder and

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.