Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Ok, I've read the documentation for the <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/String.html#replace%28%29" rel="nofollow noreferrer">replace()</a> method.</p> <p>There are two key things:</p> <ol> <li>You can use <strong>$&amp;</strong> to get the matched substring. A lot of handy and weird looking symbols there.</li> <li><strong>Use a second string</strong> when replacing, otherwise you end up in an endless loops and tiny black wholes keep spawning every now and then.</li> </ol> <p>Here's how the correct version of the function looks:</p> <pre><code>function addLinks(pattern:RegExp,text:String):String{ var result = ''; while(pattern.test(text)) result = text.replace(pattern, "&lt;font color=\"#0000dd\"&gt;&lt;a href=\"$&amp;\"&gt;$&amp;&lt;/a&gt;&lt;/font&gt;"); if(result == '') result+= text;//if there was nothing to replace return result; } </code></pre> <p>As Cay mentioned, a stylesheet is more apropiate for styling. Thanks for the input.</p> <p><strong>UPDATE</strong></p> <p>The RegEx listed above doesn't work when links contain the # sign. Here's an updated version of the function:</p> <pre><code>function addAnchors(text:String):String{ var result:String = ''; var pattern:RegExp = /(?&lt;!\S)(((f|ht){1}tp[s]?:\/\/|(?&lt;!\S)www\.)[-a-zA-Z0-9@:%_\+.~#?&amp;\/\/=]+)/g; while(pattern.test(text)) result = text.replace(pattern, "&lt;font color=\"#0000dd\"&gt;&lt;a href=\"$&amp;\"&gt;$&amp;&lt;/a&gt;&lt;/font&gt;"); if(result == '') result+= text;//if there was nothing to replace return result; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload