Skip to content

Instantly share code, notes, and snippets.

@mottet-dev
Created June 10, 2019 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mottet-dev/9d1d6858bd3b245cfb411fa0cbf1ad1a to your computer and use it in GitHub Desktop.
Save mottet-dev/9d1d6858bd3b245cfb411fa0cbf1ad1a to your computer and use it in GitHub Desktop.
PriceFormat - Go Colly
package utils
import "regexp"
func FormatPrice(price *string) {
r := regexp.MustCompile(`\$(\d+(\.\d+)?).*$`)
newPrices := r.FindStringSubmatch(*price)
if len(newPrices) > 1 {
*price = newPrices[1]
} else {
*price = "Unknown"
}
}
func FormatStars(stars *string) {
if len(*stars) >= 3 {
*stars = (*stars)[0:3]
} else {
*stars = "Unknown"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment