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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:35:12+00:00 2026-05-27T22:35:12+00:00

This has been driving me crazy. I need to construct a single regex expression

  • 0

This has been driving me crazy.

I need to construct a single regex expression of a whitelist of urls to allow my site to link to.
They should be of the form:

*.microsoft.com/*

So the following urls are valid:

http://digital.microsoft.com/audio/somefile.wmv
http://sharepoint.microsoft.com/pages/p1

And the following invalid:

http://badsite.microsoft.com.me
http://www.microsoft.com.me/runthis

I need a regex expression which will allow valid microsoft sites to be linked to, but block malicious sites which my submit links with the words microsoft.com in them.

Any help is appreciated!

UPDATE

Based on the answer by @ruakh, I was able to tweak the expression to match my scenario:
I will mark his post as the answer.

Expression: ^([a-z|A-Z])+?://([^/]+[.])?(microsoft[.]com|MICROSOFT[.]COM)?(/.*)?$

This expression correctly matches the following:

  • http://test.microsoft.com/?page=1 http://msevents.microsoft.com
  • https://myevents.microsoft.com/somesubsite/Event.aspx?EventID=56456&Culture=en-US
  • mms://digital.microsoft.com/456/videos/23800_str.wmv
  • http://go.microsoft.com/?linkid=9775098
  • http://GO.MICROSOFT.COM/?linkid=9775098

And correctly does not match the following:

  • http://me.microsoft.com.au
  • http://microsoft.com.mysite.com
  • http://microsoft.com.mysite.com/blah
  • mms://microsoft.com.mysite.com
  • 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-05-27T22:35:14+00:00Added an answer on May 27, 2026 at 10:35 pm

    I think it would be better to use a URL-parsing library, but since you say you need “a single regex expression” (emphasis mine), I take it that, for some externally-driven reason, you really need to do this in a regex? In that case, I’d probably write something like:

    ^(https?|mms)://([^/]+[.])?(?i:microsoft[.]com)(/.*)?$
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This has been driving me crazy all day. I need to get a font
This has been driving me crazy for a few days. Why doesn't the following
This has been driving me crazy for the past few minutes I have a
This has been driving me crazy for the past couple of hours. I have
This has been driving me crazy for 2 days. I have been trying to
This has been driving me crazy! It must be something simple. Here is my
This has been driving me crazy for the better part of the day. I've
This has been driving me crazy for a few days now. I have an
This has been driving be crazy, but I can't seem to find an answer.
This has been driving me crazy for the last couple of hours. I am

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.