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

  • Home
  • SEARCH
  • 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 7504309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:31:58+00:00 2026-05-29T21:31:58+00:00

This is a regex where string must start and end with an alphanumeric character

  • 0

This is a regex where string must start and end with an alphanumeric character and can contain alphanumeric characters and dashes.

/^[a-zA-Z0-9]{1}[a-zA-Z0-9\-]+[a-zA-Z0-9]{1}$/

How can I make sure that the consecutive dashes are not allowed? for example:

should allow: some-string

should NOT allow: some--string

Thanks

Edit: I want to allow several dashes, just not consecutively. for example “some-thing-here” is OK, and “some–thing” is NOT.

  • 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-29T21:32:00+00:00Added an answer on May 29, 2026 at 9:32 pm

    No need for complicated patterns with optional dashes just use this:

    /^[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*$/
    

    See it here on Regexr

    Start with at least one alphanumeric. Then there can be a dash followed by at least one alphanumerics 0 ore more times.

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

Sidebar

Related Questions

Situation: text: a string R: a regex that matches part of the string. This
Really got stuck on this simple regex. Need it to validate a string, that
I realise this must be a really easy piece of regex, but just can't
Why doesn't .NET regex treat \n as end of line character? Sample code: string[]
I wrote a regex that validates an input string. It must have a minimum
I have a string and need a RegEx Pattern for this, so I can
Given a string, how do I express that a pattern must match multiple regex
I have this regex: private static final String SPACE_PATH_REGEX =[a-z|A-Z|0-9|\\/|\\-|\\_|\\+]+; I check if my
This simple regex matching returns a string instead of an object on every browser
I have a string of this format 1.0.x.0 I have to write a regex

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.