https://github.com/mvdan/xurls
Extract urls from text
https://github.com/mvdan/xurls
extract-urls go tld
Last synced: 2 days ago
JSON representation
Extract urls from text
- Host: GitHub
- URL: https://github.com/mvdan/xurls
- Owner: mvdan
- License: bsd-3-clause
- Created: 2015-01-12T01:28:46.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2025-02-22T14:31:19.000Z (about 2 months ago)
- Last Synced: 2025-04-03T11:03:07.474Z (9 days ago)
- Topics: extract-urls, go, tld
- Language: Go
- Size: 439 KB
- Stars: 1,214
- Watchers: 23
- Forks: 117
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- awesome-go - xurls - Extract urls from text. (Text Processing / Scrapers)
- my-awesome - mvdan/xurls - urls,go,tld pushed_at:2025-02 star:1.2k fork:0.1k Extract urls from text (Go)
- project-awesome - mvdan/xurls - Extract urls from text (Go)
- go-awesome - xurls - Extract URLs from text (Open source library / Word Processing)
- awesome-go - xurls - Extract urls from text. Stars:`1.2K`. (Text Processing / Scrapers)
- awesome-golang-repositories - xurls
- awesome-go - xurls - Extract urls from text - ★ 377 (Text Processing)
- awesome-go-extra - xurls - 01-12T01:28:46Z|2022-08-03T11:54:32Z| (Bot Building / Scrapers)
README
# xurls
[](https://pkg.go.dev/mvdan.cc/xurls/v2)
Extract urls from text using regular expressions. Requires Go 1.23 or later.
```go
import "mvdan.cc/xurls/v2"func main() {
rxRelaxed := xurls.Relaxed()
rxRelaxed.FindString("Do gophers live in golang.org?") // "golang.org"
rxRelaxed.FindString("This string does not have a URL") // ""rxStrict := xurls.Strict()
rxStrict.FindAllString("must have scheme: http://foo.com/.", -1) // []string{"http://foo.com/"}
rxStrict.FindAllString("no scheme, no match: foo.com", -1) // []string{}
}
```Since API is centered around [regexp.Regexp](https://pkg.go.dev/regexp#Regexp),
many other methods are available, such as finding the [byte indexes](https://pkg.go.dev/regexp#Regexp.FindAllIndex)
for all matches.The regular expressions are compiled when the API is first called.
Any subsequent calls will use the same regular expression pointers.#### cmd/xurls
To install the tool globally:
go install mvdan.cc/xurls/v2/cmd/xurls@latest
```shell
$ echo "Do gophers live in http://golang.org?" | xurls
http://golang.org
```