AlecSadler Posted July 14, 2017 Posted July 14, 2017 Hello friends! I am rather new to using regular expressions. So please mind my noob question. I have an instant messenger and I use in it an embeded IE control to display messages. How would I go about detecting links (http and https) and turn them into anchors <a href="https://someurl.org/blahblah">https://someurl.org/blahblah Thanks much in advance.
TheDcoder Posted July 15, 2017 Posted July 15, 2017 Have you tried StringRegExpReplace? EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion
AlecSadler Posted July 15, 2017 Author Posted July 15, 2017 3 minutes ago, TheDcoder said: Have you tried StringRegExpReplace? I don't know how I would go about doing this, I need to take an existing string and put it into an anchor link. Could you please show an example?
TheDcoder Posted July 15, 2017 Posted July 15, 2017 You can make a RegEx (or find it from the internet) for detecting the URLs and append the detected urls with the HTML tags... If you actually do not know how RegEx works, I suggest you to wait for someone else with a magical RegEx pattern to post here, we have a lot of RegEx wizards in the forums EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion
InunoTaishou Posted July 15, 2017 Posted July 15, 2017 (edited) Could also use a RichEdit control to handle the hyperlinked text for you. Edited July 15, 2017 by InunoTaishou
mikell Posted July 15, 2017 Posted July 15, 2017 (edited) This raw example assumes that the links in the text are ending with white spaces. If it is not the case then the pattern must be adapted in the regular expression Local $text = "here is a link https://someurl.org/blahblah in the text, " & @crlf & _ "and here is http://otherurl.org/blah another one" $text = StringRegExpReplace($text, '(https?\S+)', '<a href="$1">$1</a>') Msgbox(0,"", $text) Edited July 15, 2017 by mikell
AlecSadler Posted July 15, 2017 Author Posted July 15, 2017 16 hours ago, mikell said: This raw example assumes that the links in the text are ending with white spaces. If it is not the case then the pattern must be adapted in the regular expression Local $text = "here is a link https://someurl.org/blahblah in the text, " & @crlf & _ "and here is http://otherurl.org/blah another one" $text = StringRegExpReplace($text, '(https?\S+)', '<a href="$1">$1</a>') Msgbox(0,"", $text) Thanks, this works perfect for links that are followed by a white-space, but what about raw links sent without any white spaces behind them? How to go about detecting a link when not followed by a space? (how do I detect the end of the link when there's nothing following it)
mikell Posted July 16, 2017 Posted July 16, 2017 (edited) Did you try my code in this case ? Local $text = "here is a link https://someurl.org/blahblah" $text = StringRegExpReplace($text, '(https?\S+)', '<a href="$1">$1</a>') Msgbox(0,"", $text) If it doesn't work then please provide all the precise requirements - may links be enclosed by other characters and which ones The best would be to post a txt with some examples of the string(s) you have to treat Edited July 16, 2017 by mikell
AlecSadler Posted July 17, 2017 Author Posted July 17, 2017 On 7/16/2017 at 1:40 AM, mikell said: Did you try my code in this case ? Local $text = "here is a link https://someurl.org/blahblah" $text = StringRegExpReplace($text, '(https?\S+)', '<a href="$1">$1</a>') Msgbox(0,"", $text) If it doesn't work then please provide all the precise requirements - may links be enclosed by other characters and which ones The best would be to post a txt with some examples of the string(s) you have to treat Okay this code is working as I need it to, no changes needed!
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