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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:02:04+00:00 2026-05-21T05:02:04+00:00

I am currently using the following regular expression: ^[a-zA-Z]{0,}(\\*?)?[a-zA-Z0-9]{0,} to check a string to

  • 0

I am currently using the following regular expression:

^[a-zA-Z]{0,}(\\*?)?[a-zA-Z0-9]{0,}

to check a string to start with an alpha character and end with alphanumeric characters and have an asterisk(*) anywhere in the string but only a maximum of one time. The problem here is that if the given string still passes if it starts with a number but doesn’t have an *, which should fail. How can I rework the regex to fail this case?

ex.

TE - pass

*TE - pass

TE* - pass

T*E - pass

*9TE - pass

*TE* - fail (multiple asterisk)

9E - fail (starts with number)

EDIT:
Sorry to introduce a late edit but I also need to ensure that the string is 8 characters or less, can I include that in the regex as well? Or should I just check the string length after the regex validation?

  • 1 1 Answer
  • 1 View
  • 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-21T05:02:05+00:00Added an answer on May 21, 2026 at 5:02 am

    This passes your example:

    "^([a-zA-Z]+\\*?|\\*)[a-zA-Z0-9]*$"
    
    It says:
      start with: [a-zA-Z]+\\*? (a letter and maybe a star)
                  | (or)
                  \\* a single star
      and end with [a-zA-Z0-9]* (an alphanumeric character)
    

    Code to test it:

    public static void main(final String[] args) {
        final Pattern p = Pattern.compile("^([a-zA-Z]+\\*?|\\*)\\w*$");
    
        System.out.println(p.matcher("TE").matches());
        System.out.println(p.matcher("*TE").matches());
        System.out.println(p.matcher("TE*").matches());
        System.out.println(p.matcher("T*E").matches());
        System.out.println(p.matcher("*9TE").matches());
        System.out.println(p.matcher("*TE*").matches());
        System.out.println(p.matcher("9E").matches());
    }
    

    Per Stargazer, if you allow alphanumeric before the star, then use this:

    ^([a-zA-Z][a-zA-Z0-9]*\\*?|\\*)\\w*$
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently using the following regular expression to validation URLs: ^(?#Protocol)(?:(?:ht|f)tp(?:s?)\:\/\/|~\/|\/)?(?#Username:Password)(?:\w+:\w+@)? (?#Subdomains)(?:(?:[-\w]+\.)+(?#TopLevel Domains)(?:com|org|net|gov|mil|biz|edu|info|mobi|name|aero|jobs|museum|travel|[a-z]{2}))(?#Port)(?::[\d]{1,5})?(?#Directories)(?:(?:(?:\/(?:[-\w~!$+|.,=]|%[a-f\d]{2})+)+|\/)+|\?|#)?(?#Query)(?:(?:\?(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=?(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)(?:&(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=?(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)*)*(?#Anchor)(?:#(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)?$ I
I've written a Regular expression which should validate a string using the following rules:
I'm currently using the following code (C#): private static void PlayLoop(string filename) { Audio
I am currently using the following script to set this value as a String:
I am attempting to parse a string like the following using a .NET regular
I'm trying to extract/match data from a string using regular expression but I don't
I am using the following regular expression in Javascript: comment_body_content = comment_body_content.replace( /(<span id=sc_start_commenttext-.*<\/span>)((.|\s)*)(<span
I've been trying to do the following using VBs Regular Expression object but could
I am currently doing a bunch of processing on a string using regular expressions
I'm using the following regular expression <a href=[^/] to find all links which do

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.