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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:36:20+00:00 2026-05-27T03:36:20+00:00

I wrote a regex that validates an input string. It must have a minimum

  • 0

I wrote a regex that validates an input string. It must have a minimum length of 8 chars (composed by alphanumeric and punctuation chars) and it must have at least one digit and one alphabetic char. So I’ve come up with the regex:

^(?=.*[0-9])(?=.*[a-zA-Z])[a-zA-Z0-9-,._;:]{8,}$

Now I have to rewrite this regex in a language that doesn’t support lookahead, how should I rewrite that regex?

Valid inputs are:

1foo,bar
foo,bar1
1fooobar
foooobar1
fooo11bar
1234x567
a1234567

Invalid inputs:

fooo,bar
1234-567
.1234567
  • 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-27T03:36:21+00:00Added an answer on May 27, 2026 at 3:36 am

    There are two approaches. One is to compose a single expression which handles all possible alternatives:

    ^[a-zA-Z][0-9][a-zA-Z0-9-,._;:]{6,}$
      |
    ^[a-zA-Z][a-zA-Z0-9-,._;:][0-9][a-zA-Z0-9-,._;:]{5,}$
      |
    ^[a-zA-Z][a-zA-Z0-9-,._;:]{2}[0-9][a-zA-Z0-9-,._;:]{4,}$
    

    etc. This is a combinatoric nightmare, but it would work.

    A much simpler approach is to validate the same string twice using two expressions:

    ^[a-zA-Z0-9-,._;:]{8,}$          # check length and permitted characters
    

    and

    [a-zA-Z].*[0-9]|[0-9].*[a-zA-Z]  # check required characters
    

    EDIT: @briandfoy correctly points out that it will be more efficient to search for each required character separately:

    [a-zA-Z]                         # check for required alpha
    

    and

    [0-9]                            # check for required digit
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote this regex with the idea that it will match any string in
I'm trying to write a regular expression that validates a date. The regex needs
I want to write a regex that matches if a string contains XYZ but
I have been trying to write a regex that will remove whitespace following a
How do I write a .net regex which will match a string that does
I wrote a regex to fetch string from HTML, but it seems the multiline
I have a SharePoint web part that I wrote in C# which is used
Using HTML5 I have an input field that should validate against a dollar amount
I am attempting to write a regex that validates any of the following cases:
Does anyone use have a good regex library that they like to use? Most

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.