package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`#[a-f0-9]{6}(?:,\s*#[a-f0-9]{6})?`)
var str = `style=\"color: rgb(255,0,24)\"
style=\"color: rgb(255, 0, 24)\"
style=\"color: rgba(255, 0, 24, .5)\"
style=\"color: hsla(170, 23%, 25%, 0.2 )\"
style=\"color: #fff\"
style=\"color: #f2ewq\" this isn\'t a color
style=\"color: #0f243e\"
style=\"color: #0f243e,#3f54ae\"
style=\"color: #0f243eпп\" здесь кириллические буквы пропустило
style=\"color: #0f243eбб,#3f54aeпп\" здесь кириллические буквы пропустило
style=\"color: 0x00ffff\" This is a color with the \`#\` escaped
.foo{
color: rgb(255,0,24);
color: rgb(255, 0, 24);
color: rgba(255, 0, 24, .5);
color: hsla(170, 23%, 25%, 0.2 );
color: #fff;
color: rgba(#fff, .5) This shows it works with SASS
color: #f2ewq; this isn\'t a color
color: 0f243e;
color: #0f243e,#3f54ae;
color: 0x00ffff; This is a color with the \`#\` escaped
}`
if len(re.FindStringIndex(str)) > 0 {
fmt.Println(re.FindString(str),"found at index",re.FindStringIndex(str)[0])
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Golang, please visit: https://golang.org/pkg/regexp/