Groovy web console

subscribe to the feed Subscribe
to this
site

WrapUrlInAHTMLLink

Published 9 years ago by Romain with tags groovy ulr link string
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
def wrapUrlInAHTMLLink(String string){
    return string.replaceAll("\\b(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]", "<a href=\"\$0\">\$0</a>")
}

assert(wrapUrlInAHTMLLink("Salut voici mon url : http://localhost:8443/test-url/tata?id=5&toto=10, tu l'as trouve comment ?")==
'''Salut voici mon url : <a href="http://localhost:8443/test-url/tata?id=5&toto=10">http://localhost:8443/test-url/tata?id=5&toto=10</a>, tu l'as trouve comment ?'''
)