mvdan / xurls

Extract urls from text
BSD 3-Clause "New" or "Revised" License
1.19k stars 116 forks source link

Replace/Positions #38

Closed tcurdt closed 4 years ago

tcurdt commented 4 years ago

Finding the links and then searching for them to replace them feels rather inefficient.

It would be great if the API would also allow for link replacements. Or just return position information (start, stop/len) of the urls being found.

mvdan commented 4 years ago

The API is a Go regexp, so its methods already allow you to obtain the matching offsets, for example. The xurls command-line tool uses them if you want an example.

tcurdt commented 4 years ago

Ahhh, thanks for the quick reply. I didn't realize that from the README.

Neither this

rxStrict.FindAllString("must have scheme: http://foo.com/.", -1) // []string{"http://foo.com/"}

nor Note that the funcs compile regexes, so avoid calling them repeatedly were clear on this.

mvdan commented 4 years ago

Thanks for the suggestion! I've just pushed 8d3a99a85f5f22008b2fa1c5bf3521107631413f to be a bit clearer.