title: PHP Regular expression to disallow too short urls
body: <p>I have a regular expression that finds urls in text and replaces them with links</p>
  
  <pre><code>preg_replace( '@(?&lt;![.*"&gt;])\b(?:(?:https?|ftp|file)://|[a-z]\.)[-A-Z0-9+&amp;#/%=~_|$?!:,.]*[A-Z0-9+&amp;#/%=~_|$]@i', '&lt;a href="\0" target="_blank" rel="nofollow"&gt;\0&lt;/a&gt;', $text );
  </code></pre>
  
  <p>The problem is, when someone types text that contains "i.e" it converts it also to a link, which should not happen. How do I limit this regular expression to replace strings longer than 3 characters?</p>
  
  <p>I tried putting <code>{3,}</code>, but it's not working.</p>
  
  <pre><code>preg_replace( '@(?&lt;![.*"&gt;])\b(?:(?:https?|ftp|file)://|[a-z]\.)
  ([-A-Z0-9+&amp;#/%=~_|$?!:,.]{3,})*[A-Z0-9+&amp;#/%=~_|$]@i', '
  &lt;a href="\0" target="_blank" rel="nofollow"&gt;\0&lt;/a&gt;', $text );
  </code></pre>