title: Regex matches only part of a URL - why?
body: <p>I am very weak in regex and the regex I am using (found from internet) is only partially solving my problem. I need to  add an anchor tag to a URL from text input using java. Here is my code:</p>
  
  <pre><code>String text ="Hi please visit www.google.com";
  String reg = "\\b(([\\w-]+://?|www[.])[^\\s()&lt;&gt;]+(?:\\([\\w\\d]+\\)|([^[:punct:]\\s]|/)))";
          String s = text.replaceAll(reg, "&lt;a href='$1'&gt;$1&lt;/a&gt;");
          System.out.println(""+s);
  </code></pre>
  
  <p>The output currently is <code>Hi please visit &lt;a href='www.google.c'&gt;www.google.c&lt;/a&gt;om</code>. What's wrong with the regex?</p>
  
  <p>I need to parse a text and display a URL entered from text field as hot link in a jsp page. The actual output expected would be</p>
  
  <pre><code>Hi please visit &lt;a href='www.google.com'&gt;www.google.com&lt;/a&gt;
  </code></pre>
  
  <p><strong>Edit</strong></p>
  
  <p>Following regex </p>
  
  <pre><code>(http(s)?://)?(www(\.\w+)+[^\s.,"']*)
  </code></pre>
  
  <p>works like a charm in url ending with <code>.com</code> but fails in other extensions like <code>.jsp</code>.Is there any way for it to work in all sort of extension?</p>