golangbyexamples.com<\/a> in the output as that is without a scheme.<\/p>\n\n\n\nLet’s see another program to extract multiple URLs<\/p>\n\n\n\n
package main\n\nimport (\n\t\"fmt\"\n\n\t\"mvdan.cc\/xurls\/v2\"\n)\n\nfunc main() {\n\txurlsStrict := xurls.Strict()\n\tinput := \"The webiste is https:\/\/golangbyexamples.com:8000\/tutorials\/intro amd mail to mailto:contactus@golangbyexamples.com\"\n\toutput := xurlsStrict.FindAllString(input, -1)\n\tfmt.Println(output)\n}<\/code><\/pre>\n\n\n\nOutput<\/strong><\/p>\n\n\n\n[https:\/\/golangbyexamples.com:8000\/tutorials\/intro mailto:contactus@golangbyexamples.com]<\/code><\/pre>\n\n\n\nIf we want to restrict the output to a particular scheme then that also can be done.<\/p>\n\n\n\n
package main\n\nimport (\n\t\"fmt\"\n\t\"log\"\n\n\t\"mvdan.cc\/xurls\/v2\"\n)\n\nfunc main() {\n\txurlsStrict, err := xurls.StrictMatchingScheme(\"https\")\n\tif err != nil {\n\t\tlog.Fatalf(\"Some error occured. Error: %s\", err)\n\t}\n\tinput := \"The webiste is https:\/\/golangbyexamples.com:8000\/tutorials\/intro amd mail to mailto:contactus@golangbyexamples.com\"\n\toutput := xurlsStrict.FindAllString(input, -1)\n\tfmt.Println(output)\n}<\/code><\/pre>\n\n\n\nOutput<\/strong><\/p>\n\n\n\n[https:\/\/golangbyexamples.com:8000\/tutorials\/intro]<\/code><\/pre>\n\n\n\nIn the above program, we provided the scheme as https which is why we have only one output<\/p>\n","protected":false},"excerpt":{"rendered":"
Table of Contents OverviewProgram Overview Below go package can be used to extract URL from a given string https:\/\/github.com\/mvdan\/xurls There are two ways of using this package Strict – In strict mode,…<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[1],"tags":[3,4],"class_list":["post-6025","post","type-post","status-publish","format-standard","hentry","category-tech","tag-go","tag-golang"],"yoast_head":"\n
Extract a URL from a string in Go (Golang) - Welcome To Golang By Example<\/title>\n \n \n \n \n \n \n \n \n \n \n \n \n \n\t \n\t \n\t \n