我正在尝试将包含URL的字符串替换为浏览器兼容的链接URL。
我的初始字符串看起来像这样:
"hello, i'm some text with an url like http://www.the-url.com/ and I need to have an hypertext link !"
我想要得到一个看起来像这样的字符串:
"hello, i'm some text with an url like <a href="http://www.the-url.com/">http://www.the-url.com/</a> and I need to have an hypertext link !"
我可以使用这行代码来捕获URL:
String withUrlString = myString.replaceAll(".*://[^<>[:space:]]+[[:alnum:]/]", "<a href=\"null\">HereWasAnURL</a>");
可能正则表达式需要进行一些修正,但它能够正常工作,需要进一步测试。
因此问题是如何保留被正则表达式捕获的表达式,并仅添加所需的内容以创建链接:被捕获的字符串
非常感谢您的关注和回复!