Results 1 to 2 of 2

Thread: .htaccess and regex

  1. #1
    Join Date
    Feb 2010

    .htaccess and regex

    I was using this to test my regular expression:


    And tried to match

    http://www.website.com/index.php?=other things

    to pull out the index.php portion

    We've all seen

    ^(.*)/index.php or some variant, but it never works because .* is greedy and doesn't stop before getting through index.php.

    I tried the negative assertion
    ^(.*)(?!index.php), but again .* was too greedy. The fact that this failed was really surprising because when I just did /(?!index.php), every slash matched exceopt the one before index.php. You'd think using the * would help that along.

    Anyway, if you have any ideas, I'd appreciate it

  2. #2
    Join Date
    Apr 2010
    Evidently regexpal doesn't understand what '(some expression)' means. Try http://www.regextester.com/ for better results. For a free offline tester try this: http://www.weitz.de/regex-coach/ . Good luck

    /(.*)?index\.php/ gives you 'http://www.website.com/'
    /.*?index\.php\?(.*)/ gives you '=other things'
    and , of course,
    /(index\.php)/ gives you 'index.php'

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center