EKY32 Posted January 26, 2015 Share Posted January 26, 2015 (edited) Hello, i'm not good using StringRegExp function, may I have some help to make a function that replaces the plain text links with regular HTML anchor tags? I found a JavsScript sample that may help. function replaceURLWithHTMLLinks(text) { var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; return text.replace(exp,"<a href='$1'>$1</a>"); } Thank you. Edited January 26, 2015 by EKY32 [font="'trebuchet ms', helvetica, sans-serif;"]Please mark the answer of your question if you found it.[/font] Link to comment Share on other sites More sharing options...
Moderators Solution SmOke_N Posted January 26, 2015 Moderators Solution Share Posted January 26, 2015 (edited) Did you try just copy and pasting? Func _replaceURLWithHTMLLinks($sText) Local Const $sExp = "(?i)(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])" Return StringRegExpReplace($sText, $sExp, "<a href='$1'>$1</a>") EndFunc Edit: Although, I'd probably have changed it up a bit, something like: ConsoleWrite(_replaceURLWithHTMLLinks("http://www.autoitscript.com/forum/topic/167033-replace-plain-urls-with-links/") & @CRLF) ConsoleWrite(_replaceURLWithHTMLLinks("http://www.autoitscript.com/forum/topic/167033-replace-plain-urls-with-links/", "Click Me") & @CRLF) Func _replaceURLWithHTMLLinks($sURL, $sOutText = "") $sOutText = ((IsKeyword($sOutText) Or Not StringLen($sOutText)) ? "$1" : _ StringRegExpReplace($sOutText, "(\$|\\)", "\\$1")) Local Const $sExp = "(?i)(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])" Return StringRegExpReplace($sURL, $sExp, "<a href='$1'>" & $sOutText & "</a>") EndFunc Edited January 26, 2015 by SmOke_N EKY32 1 Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
EKY32 Posted January 26, 2015 Author Share Posted January 26, 2015 (edited) That's it thank you very much. Edited January 26, 2015 by EKY32 [font="'trebuchet ms', helvetica, sans-serif;"]Please mark the answer of your question if you found it.[/font] Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now