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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:17:04+00:00 2026-06-02T04:17:04+00:00

I am designing a regex to use in some IIS Url Rewrites. The intent

  • 0

I am designing a regex to use in some IIS Url Rewrites. The intent is to capture urls which:

  1. Are not just a file (as identified by containing a period) in the root directory, and
  2. Do not contain a querystring, and
  3. Do not belong to a specific set of sub-directories, specifically “Account” and “Public”

My current regex looks like:

^(?!(Account)|(Public))([^./]+)(/[^?]*)?$

Using RegexPal with the test set of:

file.aspx
Account/otherfile.aspx
Public/otherfile.aspx
otherfolder1/otherfile.aspx?stuff=otherstuff
otherfolder2/otherfolder/otherfile.aspx
otherfolder3/
otherfolder4

My regex correctly ignores the first two cases, but it is still matching on the third case. What is wrong with the lookahead here?

  • 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-02T04:17:06+00:00Added an answer on June 2, 2026 at 4:17 am

    As reported by sln, the problem with these tests in RegexPal is that running a multi-line test enables multiple lines to group together to create a single match when they otherwise shouldn’t.

    The regex is fine for the purposes that it is designed to fulfill. It’s actually overkill. For IIS Rewrites and Redirects, if you are using the IIS URL Rewrite Module, you have the option of specifying conditions on which it will or will not accept matches. Some of those options include:

    • Item is not a physical file
    • Item is not a physical directory
    • Item does (or does not) match a secondary pattern

    These will achieve the desired effect more completely than the negative-lookahead.

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

Sidebar

Related Questions

While designing a new WPF application I noticed exceptions not being thrown during data
When designing both the domain-model and class-diagrams I am having some trouble understanding what
for designing purposes i need to truncate all DB which has lots of FK's.
I have a complex regex, which contains constructs like this one: ( + sectionPattern
Is there any application for a regex split() operation that could not be performed
I designing an programming a website using Symfony2. I completed some parts and checked
Alright, i promised myself i would learn Regex one day.. but today is not
When designing a ASP.net WebForm application what are some important steps to take (or
Im designing a dialerPad form using Windows form, there is a textbox which should
When designing an API for our web app, we'll use the their subdomain as

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.