Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mvdan/xurls
Extract urls from text
https://github.com/mvdan/xurls
extract-urls go tld
Last synced: 9 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 (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2024-10-01T14:55:55.000Z (about 1 month ago)
- Last Synced: 2024-10-26T14:29:56.946Z (13 days ago)
- Topics: extract-urls, go, tld
- Language: Go
- Size: 440 KB
- Stars: 1,182
- Watchers: 24
- Forks: 116
- 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:2024-10 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
[![Go Reference](https://pkg.go.dev/badge/mvdan.cc/xurls/v2.svg)](https://pkg.go.dev/mvdan.cc/xurls/v2)
Extract urls from text using regular expressions. Requires Go 1.22 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
```