JSFiddle - React, Tailwind, and code Playground

JavaScript

var source = "var x=4; var testURL = 'http://images.raaga.com/catalog/cd/A/A0000102.jpg'; callAFunction(5,'red leaves');";

/*var urlpattern = new RegExp( "(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?";
  */                           
var urlpattern2 = /(http|ftp|https):\/\/[\w-]+(\.[\w-]+)+([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?/
                             

    if ( urlpattern2.test(source) ){
        document.write("hello");
    
 }