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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:59:14+00:00 2026-05-31T09:59:14+00:00

This Regex ([a-zA-Z0-9]?(?:http[s]?://)?(?:(?:\w+)\.)(?:\S+)(?:\.(?:\w+))+?) successfully finds any occurances of http://www.msn.com or www.msn.com or msdn.microsoft.com or

  • 0

This Regex ([a-zA-Z0-9]?(?:http[s]?://)?(?:(?:\w+)\.)(?:\S+)(?:\.(?:\w+))+?) successfully finds any occurances of http://www.msn.com or www.msn.com or msdn.microsoft.com or http://msdn.microsoft.com inside of a string. However, there are two replace algorithms that I need to use, this one <a href=\"$1\" target=\"_blank\" onclick=\"preventDualEditing(event)\">$1</a> and this one <a href=\"http://$1\" target=\"_blank\" onclick=\"preventDualEditing(event)\">$1</a>. Note the difference is that one prefixes the string with an http:// which is necessary for the links like www.msn.com.

But, what’s happening is the loop that I use the replace statements in is messing things up because if it’s trying to replace the www.msn.com the first occurance found is http://www.msn.com and so it replaces it multiple times – once when it finds the link with an http:// already and once when it find www.msn.com.

Is there a way for me to have a one pass replacement that would conditionally add the http:// to the string if necessary?

  • 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-31T09:59:15+00:00Added an answer on May 31, 2026 at 9:59 am

    Try with this:

    ([a-zA-Z0-9]?http[s]?://)?((?:(?:\w+)\.)(?:\S+)(?:\.(?:\w+))+?)
    

    and use $2 instead of $1

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

Sidebar

Related Questions

I'm using @diegoperini's regex to validate URL's, However this: http://domain.com/#foo -> Matches http://domain.com#foo ->
I am using this tool to build a regex http://www.gethifi.com/tools/regex I found that the
I use this regex for URL's: var re = /^(http[s]?:\/\/){0,1}(www\.){0,1}[a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,5}[\.]{0,1}/; However, it seems to
I have this regex: /.*v\=([\w-]+).*(&autoplay\=1)?/ Which I am trying to match against: http://www.youtube.com/watch?v=awmLS6GCJno&width=1000&height=300&autoplay=1 This
This Regex Pattern: \bgoogle\b Test case: http://www.google.com/ It matches. Why?
I built up this regex at http://regextester.com to parse YSOD but VS is complaining
I've created this regex (www|http://)[^ ]+ that match every http://... or www.... but I
Something like this: http://perl.plover.com/yak/regex/samples/slide083.html In other words I want to match successfully on {
What am I doing wrong with this regex. My requested url http://domain.com/local/v11/full/#Q73Ps/ What I
This regex (<link\s+)((rel=[Ii]con\s+)|(rel=[Ss]hortcut [Ii]con\s+))(href=(.+))(.+)/> works for <link rel=icon href=http://passets-cdn.pinterest.com/images/favicon.png type=image/x-icon /> <link rel=shortcut icon

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.