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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:09:52+00:00 2026-06-13T11:09:52+00:00

I’m trying to usa a regex which only matches string which doesn’t start with

  • 0

I’m trying to usa a regex which only matches string which doesn’t start with some other string. As far as I know and from some other questions here on Stack Overflow I should use a negative look-ahead assertion. But for some reason it doesn’t seem to work. Consider the following three strings:

/match.jpg
match.png
excludedpath/no-match.gif

I want my regex pattern to only match the first two strings, because the last string starts with excludepath/. What I have tried is the following:

(?!excludedpath\/)(.*)\.(gif|jpg|png)$

I want to use this regex pattern in a rewrite rule for Apache. Basically I want to simply load all images (with those three extensions) unless they are in the format of http://example.com/excludedpath/some-image.jpg:

RewriteCond %{REQUEST_FILENAME} (?!excludedpath\/)(.*)\.(gif|jpg|png)$
RewriteRule ^(.*)$ $1 [L]

RewriteCond "/my/path/to/application/%{REQUEST_URI}" !-f
RewriteRule ^(.*)$ /index.php/$1 [L]

Anybody can tell me why it still matches all three strings: This Link and how to fix it?

  • 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-13T11:09:53+00:00Added an answer on June 13, 2026 at 11:09 am

    It’s because you don’t require the lookahead to look at the beginning of your string. Just add another anchor:

    ^(?!excludedpath\/)(.*)\.(gif|jpg|png)$
    

    Otherwise, the engine will of course fail to match at the first character (because the lookahead kicks in), but then it will gladly try to match from the second character. And of course xcludedpath... does not set off the negative lookahead.

    Since your rubular example has the last string start with a slash, you could add an optional slash to the lookahead, if you want to exclude both variants:

    ^(?!\/?excludedpath\/)(.*)\.(gif|jpg|png)$
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
Does anyone know how can I replace this 2 symbol below from the string
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Specifically, suppose I start with the string string =hello \'i am \' me And
I'm trying to select an H1 element which is the second-child in its group
I have a text area in my form which accepts all possible characters from
I know there's a lot of other questions out there that deal with this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

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.