title: JavaScript Regex to match a URL in a field of text
body: <p>How can I setup my regex to test to see if a URL is contained in a block of text in javascript. I cant quite figure out the pattern to use to accomplish this</p>
  
  <pre><code> var urlpattern = new RegExp( "(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;amp;:/~\+#]*[\w\-\@?^=%&amp;amp;/~\+#])?"
  
   var txtfield = $('#msg').val() /*this is a textarea*/
  
   if ( urlpattern.test(txtfield) ){
          //do something about it
   }
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>So the Pattern I have now works in regex testers for what I need it to do but chrome throws an error</p>
  
  <pre><code>  "Invalid regular expression: /(http|ftp|https)://[w-_]+(.[w-_]+)+([w-.,@?^=%&amp;amp;:/~+#]*[w-@?^=%&amp;amp;/~+#])?/: Range out of order in character class"
  </code></pre>
  
  <p>for the following code:</p>
  
  <pre><code>var urlexp = new RegExp( '(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;amp;:/~\+#]*[\w\-\@?^=%&amp;amp;/~\+#])?' );
  </code></pre>