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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:17:35+00:00 2026-06-07T02:17:35+00:00

Our web application allows users to specify their own slugs which can include relative

  • 0

Our web application allows users to specify their own “slugs” which can include relative paths e.g. /somedir/some-file.htm.

In our routing configuration we need to ensure that only valid slugs (with segments) are supported.

The regex I am using is:

(^[a-z0-9])([a-z0-9-/]+)([a-z0-9])$

This means:

  • A valid slug will match e.g. some-file.htm
  • A valid slug with segments (relative path) will match e.g. somedir/subdir/some-file.htm
  • Absolute URLs will NOT match e.g. /somedir/some-file.htm
  • Trailing / or – will not match e.g. -slug-

Unfortunately it also means that double slashes will match e.g. somedir//subdir//some-file.htm because my expression is allowing one or more slashes.

How can I change it to allow zero or more slashes between segments.

I thought that:

(^[a-z0-9])(/?[a-z0-9-]+/?)([a-z0-9])$

would work but it does 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-06-07T02:17:37+00:00Added an answer on June 7, 2026 at 2:17 am

    ^[a-z0-9]([a-z0-9-]*[a-z0-9])?(/[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$

    EDIT: Use this one if you like the first regex:

    ^(?!-)[a-z0-9-]+(?<!-)(/(?!-)[a-z0-9-]+(?<!-))*$

    It looks messy and complicated, but it seems to be correct per your spec.

    [a-z0-9]([a-z0-9-]*[a-z0-9])?

    Matches a single name. Ignoring /s for the moment.

    Then the rest of it is a single slash followed by that same thing again.

    As mentioned in Karoly’s answer, this does not include literal periods, for instance “some-file.htm” will not match the regex I wrote.

    If this is desired behavior then you’ll actually want:

    ^[a-z0-9]([a-z0-9-\.]*[a-z0-9])?(/[a-z0-9]([a-z0-9-\.]*[a-z0-9])?)*$

    Finally, if you want to allow literal periods in only the last section then you’ll want:

    ^[a-z0-9]([a-z0-9-]*[a-z0-9])?(/[a-z0-9]([a-z0-9-]*[a-z0-9])?)*(/[a-z0-9]([a-z0-9-\.]*[a-z0-9])?)?$

    EDIT:

    A thought occurs that this can be simplified a bit using lookaheads and behinds.

    ^[a-z0-9]([a-z0-9-]*[a-z0-9])?(/[a-z0-9]([a-z0-9-]*[a-z0-9])?)*(/[a-z0-9]([a-z0-9-\.]*[a-z0-9])?)?$

    becomes:

    ^(?!-)[a-z0-9-]+(?<!-)(/(?!-)[a-z0-9-]+(?<!-))*(/(?!-\.)[a-z0-9-\.]+(?<!-\.))?$

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

Sidebar

Related Questions

Our Web application is based on IE9, which means only IE9 can open the
We've developed a web application where people can sign-up on our website to make
I'm working on an ASP.NET web application for our corporate intranet users. I have
I have developed a web based application which allows a client/user to upload a
We have created a web application, using ASP.NET, that allows users to upload documents
We allow users to set some preferences in our web application. When they login
In our web application, we have multiple small applications availables. Let us say A,B,C.
In our web-application we manage our continuous integration using TeamCity. So far we have
For our web application, we are sending the X-UA-Compatible -> IE=EmulateIE7 for all the
On our web application I am trying to ping a 3rd party site to

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.