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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:33:01+00:00 2026-05-31T17:33:01+00:00

I’ve looked through numerous other questions up here surrounding a negative lookbehind for JavaScript

  • 0

I’ve looked through numerous other questions up here surrounding a negative lookbehind for JavaScript but I can’t seem to mimic them. I have the following Regex:

\b((?:http[s])?\S+\.\S+\.(?:\S+\.?){1,4})(?<!@)\b` 

and the basis of this Regex is it matches web addresses like:

  • www.msn.com
  • or http://www.msn.com
  • or https://www.google.com
  • or http://msdn.microsoft.com.

However, it also matches name@d1.d2.d3.d4 because of the numerous domain names following the @ sign. I need to perform a negative lookbehind for that @ sign.

Hopefully somebody can give me a hand!

UPDATE

Updating to include the replacement string that I’m using to create the hyperlink out of the matched text.

replace(webLinkPattern, "<a href=\"http://$2\" target=\"_blank\" onclick=\"preventDualEditing(event)\">$2</a>");

UPDATE 2 – ANSWER

ts = ts.replace(webLinkPattern, function (url) {
    if (url.indexOf('@') != -1) {
        return url;
    }

    return url.replace(webLinkPattern, "<a href=\"http://$&\" target=\"_blank\" onclick=\"preventDualEditing(event)\">$&</a>");
});
  • 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-31T17:33:02+00:00Added an answer on May 31, 2026 at 5:33 pm

    JavaScript doesn’t support lookbehind assertions, so you’ll have to handle this in your own code. One option is simply to include the @ in the result, and then discard the match if the @ is there:

    replace(/(?:\b|@)(?:https?)?\S+\.\S+\.(?:\S+\.?){1,4}\b/,
            function(url) {
              if(url.indexOf('@') > -1)
                return url;
              return '<a href="' + url + ' target="_blank"' +
                     ' onclick="preventDualEditing(event)">' + url + '</a>';
            }
           );
    

    Alternatively, you can check for a preceding @ in the callback, even without including it in url:

    replace(/\b(?:https?)?\S+\.\S+\.(?:\S+\.?){1,4}\b/,
            function(url, pos, str) {
              if(pos > 0 && str.charAt(pos - 1) == '@')
                return url;
              return '<a href="' + url + ' target="_blank"' +
                     ' onclick="preventDualEditing(event)">' + url + '</a>';
            }
           );
    

    (Note that I’ve also changed http[s] to https?, which is what you meant. http[s] is the same as https, since [s] is a character class matching any character that’s s.)

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

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I am trying to render a haml file in a javascript response like so:

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.