Link Regex Fix

regex improvement for the link injection code

by nickadeemus2002

HTML

<script src="http://chrisvillanueva.com/bountytests/js/jquery.highlightMe.js"></script>
<table id="bbs">
<tbody>
   <tr class="row01">
       <td class="bbs_date" valign="top">
           Jan 31, 4:25 PM                                                                                         
       </td>
       <td class="bbs_bulletin" valign="top">
            <pre class="postingpre">
                To RSVP for this call and for call details, visit the Headhunter Intake 
                 Session page (https://qa.chrisvillanueva.com/posting/viewPhoneConferenceSchedule.do?dispatch=viewSchedule&amp;scheduleId=114).
             </pre>      
       </td>
       <td class="bbs_button" valign="top">
                  remove
       </td>
    </tr>
   <tr class="row02">
       <td class="bbs_date" valign="top">
           Nov 15, 2AM                                                                                         
       </td>
       <td class="bbs_bulletin" valign="top">
            <pre class="postingpre">
                Hey, don't change this link:
            https://www.google.com.
             </pre>      
       </td>
       <td class="bbs_button" valign="top">
                  remove
       </td>
    </tr>
   <tr class="row01">
       <td class="bbs_date" valign="top">
           Jul 9, 11:27AM                                                                                         
       </td>
       <td class="bbs_bulletin" valign="top">
            <pre class="postingpre">
               But do change this one....(https://chrisvillanueva.com/posting/viewPhoneConferenceSchedule.do?dispatch=viewSchedule&amp;scheduleId=114).
             </pre>      
       </td>
       <td class="bbs_button" valign="top">
                  remove
       </td>
    </tr>
   <tr class="row02">
       <td class="bbs_date" valign="top">
           Nov 15, 2AM                                                                                         
       </td>
       <td...

CSS

table#bbs tr td{border: 1px solid #ff0000;font-size:11px;padding:20px;}
table#bbs tr td.bbs_bulletin{border:2px solid #0101DF;}
table#bbs tr td pre.findLinks{background-color:#F2F5A9;}

JavaScript

$(document).ready(function(){
    domain = window.location.host;
    console.log(domain);
    $('pre.postingpre').each(function(i,v){
        var bbsContent = $(this).text(),
            linkPattern = /http*/gi,
            linkFound = linkPattern.test(bbsContent);
        if(linkFound){
            $(this).addClass('findLinks');
        }
    });    
    
    $('.findLinks').each(function(index,value){
        console.log(index); 
        console.log(value); 
        var bbsContent = $(this).text(),
            bbsContentLink,
            bbsLinkRegEx= new RegExp( "https?:\/\/"+domain+"[^\) \t \n]+", "gi" ),
            textToLinks = (bbsContent.match(bbsLinkRegEx));
            console.log(textToLinks);                
            $(this).highlightMe(textToLinks, "highlight", {'currentDomain':domain});
    });    
    
    
    
         
});