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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:53:16+00:00 2026-05-23T12:53:16+00:00

I am not a regex ninja. I’ve been tweaking this for an hour, and

  • 0

I am not a regex ninja. I’ve been tweaking this for an hour, and I’m sure someone on SO can do it more effectively.

This is a regex for a username with some slightly peculiar requirements (to accomodate legacy usernames).

Rules:

  • length: 24 charaters maximum, 3 characters minimum
  • must not start or end with a space
  • any number of the following (up to the max field lenght of 24):
    • 0-9
    • A-Z
    • a-z
    • . (dot)
    • ‘ ‘ (space)
  • zero or one of each from following set:
    • @ (at)
    • _ (underscore)
    • – (hyphen)
    • ‘ (apostrophy)

Here’s what I have so far:

^[^ ](?=[A-Za-z0-9. @_\-]{1,24}$)[a-zA-Z0-9_. ]*\.?[a-zA-Z0-9_]*[^ ]$

but it is not quite right. I’m not sure how to escape the ‘ (apostrophe)

also, should I use another lookahead for the characters allowed zero or one times?

Thanks.

Update:
Note that target is the .Net 4.0 regex libraries with C#

  • 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-23T12:53:16+00:00Added an answer on May 23, 2026 at 12:53 pm

    This would be a regex solution, decide on your own if this is readable/usable/maintainable for you.

    (?!^.*?([@'_-]).*\1.*$)^(?! )[\w. @'-]{3,24}(?<! )$
    

    See it here on Regexr

    (?!^.*?([@'_-]).*\1.*$) is a negative lookahead, if one of the characters you named is found it is put into capturing group 1 and to ensure this is not repeating using the backreference \1.

    ^(?! ) is a negative lookahead to ensure there is no space after the start of the string.

    [\w. @'-]{3,24} The characters you allow at least 3 at most 24 of them

    (?<! )$ is a negative lookbehind to ensure there is no space before the end of the string.

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

Sidebar

Related Questions

Please could someone explain to me why this regex does not match anything, when
I'm not a pro in Regex, therefore I'm having a difficulty translating this regex
I'm not a regex guy, so I definitely need help on this. All I
How can I create a regex NOT to match something? For example I want
why this regex not work? i want to replace my string by all not
Not a regex expert, but I know enough to be dangerous, need some help
I'm not a regex-master, but I'm looking for a regex that would give this
First, I'm not a regex expert, so I'm pretty sure I'm doing something wrong.
I want to stop out all characters that do NOT match this regex pattern:
I am not a RegEx expert and just rtying to debug some jUnit code

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.