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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:29:33+00:00 2026-06-16T01:29:33+00:00

I’m trying to come up with a regular expression that will indicate if the

  • 0

I’m trying to come up with a regular expression that will indicate if the URL provided is the index page of the site. This means it has to match example.com, example.com/ and example.com/index.php but not example.com/page.php

Here’s a list that I came up with for testing. So many permutations due to www/non-www, http/https, trailing slashes, etc.

It should match these:

  • http://example.com/index.php
  • http://example.com/
  • http://example.com
  • http://example.com/index.php?var=X
  • http://example.com/?var=X
  • http://example.com?var=X
  • https://example.com/index.php
  • https://example.com/
  • https://example.com
  • https://example.com/index.php?var=X
  • https://example.com/?var=X
  • https://example.com?var=X
  • http://www.example.com/index.php
  • http://www.example.com/
  • http://www.example.com
  • http://www.example.com/index.php?var=X
  • http://www.example.com/?var=X
  • http://www.example.com?var=X
  • https://www.example.com/index.php
  • https://www.example.com/
  • https://www.example.com
  • https://www.example.com/index.php?var=X
  • https://www.example.com/?var=X
  • https://www.example.com?var=X

It should NOT match these

  • http://example.com/page.php
  • http://example.com/page.php?var=X
  • http://example.com/page
  • http://example.com/page/
  • http://example.com/page/index.php
  • http://example.com/page?var=X
  • http://example.com/page/?var=X
  • https://example.com/page.php
  • https://example.com/page.php?var=X
  • https://example.com/page
  • https://example.com/page/
  • https://example.com/page/index.php
  • https://example.com/page?var=X
  • https://example.com/page/?var=X
  • http://www.example.com/page.php
  • http://www.example.com/page.php?var=X
  • http://www.example.com/page
  • http://www.example.com/page/
  • http://www.example.com/page/index.php
  • http://www.example.com/page?var=X
  • http://www.example.com/page/?var=X
  • https://www.example.com/page.php
  • https://www.example.com/page.php?var=X
  • https://www.example.com/page
  • https://www.example.com/page/
  • https://www.example.com/page/index.php
  • https://www.example.com/page?var=X
  • https://www.example.com/page/?var=X

(Are there any other combinations I left out?)

All I’ve come up with so far is:

example.com(/|index.php|)

which is obviously incorrect as it is matching the /page values too.

  • 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-16T01:29:34+00:00Added an answer on June 16, 2026 at 1:29 am

    This works

    ^https?://[^/]+(/(\?.*|index\.php(\?.*)?)?)?$
    

    Note this is a generic regex. To match your flavor you might need to escape.

    After running a simple test with egrep here is the result

    $ while read x 
    >       do 
    >           if  echo $x | egrep '^https?://[^/]+(/(\?.*|index\.php(\?.*)?)?)?$' > /dev/null
    >           then  
    >               echo MATCH $x
    >           else 
    >               echo NOT MATCH $x 
    >           fi
    >       done < data
    MATCH http://example.com/index.php
    MATCH http://example.com/
    MATCH http://example.com
    MATCH http://example.com/index.php?var=X
    MATCH http://example.com/?var=X
    MATCH http://example.com?var=X
    MATCH https://example.com/index.php
    MATCH https://example.com/
    MATCH https://example.com
    MATCH https://example.com/index.php?var=X
    MATCH https://example.com/?var=X
    MATCH https://example.com?var=X
    MATCH http://www.example.com/index.php
    MATCH http://www.example.com/
    MATCH http://www.example.com
    MATCH http://www.example.com/index.php?var=X
    MATCH http://www.example.com/?var=X
    MATCH http://www.example.com?var=X
    MATCH https://www.example.com/index.php
    MATCH https://www.example.com/
    MATCH https://www.example.com
    MATCH https://www.example.com/index.php?var=X
    MATCH https://www.example.com/?var=X
    MATCH https://www.example.com?var=X
    NOT MATCH http://example.com/page.php
    NOT MATCH http://example.com/page.php?var=X
    NOT MATCH http://example.com/page
    NOT MATCH http://example.com/page/
    NOT MATCH http://example.com/page/index.php
    NOT MATCH http://example.com/page?var=X
    NOT MATCH http://example.com/page/?var=X
    NOT MATCH https://example.com/page.php
    NOT MATCH https://example.com/page.php?var=X
    NOT MATCH https://example.com/page
    NOT MATCH https://example.com/page/
    NOT MATCH https://example.com/page/index.php
    NOT MATCH https://example.com/page?var=X
    NOT MATCH https://example.com/page/?var=X
    NOT MATCH http://www.example.com/page.php
    NOT MATCH http://www.example.com/page.php?var=X
    NOT MATCH http://www.example.com/page
    NOT MATCH http://www.example.com/page/
    NOT MATCH http://www.example.com/page/index.php
    NOT MATCH http://www.example.com/page?var=X
    NOT MATCH http://www.example.com/page/?var=X
    NOT MATCH https://www.example.com/page.php
    NOT MATCH https://www.example.com/page.php?var=X
    NOT MATCH https://www.example.com/page
    NOT MATCH https://www.example.com/page/
    NOT MATCH https://www.example.com/page/index.php
    NOT MATCH https://www.example.com/page?var=X
    NOT MATCH https://www.example.com/page/?var=X
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Basically, what I'm trying to create is a page of div tags, each has
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a French site that I want to parse, but am running into
I know there's a lot of other questions out there that deal with this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is

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.