How to use regex to replace URLs with HTML link in Qt?

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>")
+3
source share
1 answer

I think it (?:https?|ftp)://\\S+will do it for you.

, URL-, , , . ( , URL-, .)

+4

Source: https://habr.com/ru/post/1756250/


All Articles