How to use QString::replaceto detect URLs in a string and replace them with an HTML link, for example ...
[...].replace(QRegExp("???"), "<a href=\"\\1\">\\1</a>")
What should be the argument QRegExp? The end of the URL should be indicated by the appearance of a space character (for example, space, \ r or \ n) or the end of a line.
The regular expression should be pretty simple: http: //, https: //, ftp: // etc., followed by one or more characters without spaces, should be converted to a link.
EDIT: This is the solution I used ...
[...].replace(QRegExp("((?:https?|ftp)://\\S+)"), "<a href=\"\\1\">\\1</a>")
source
share