test := "a,b,c,d,e" aaa := test keywordSlice := strings.Split(test,",") for _,v := range keywordSlice{ reg := regexp.MustCompile("(?i)"+v) aaa = reg.ReplaceAllString(aaa,"<b class='f-red'>"+strings.ToUpper(v)+"</b>") fmt.Println(aaa) }
<b class='f-red'>A</b>,b,c,d,e
<<b class='f-red'>B</b> class='f-red'>A</<b class='f-red'>B</b>>,<b class='f-red'>B</b>,c,d,e
<<b <b class='f-red'>C</b>lass='f-red'>B</b> <b class='f-red'>C</b>lass='f-red'>A</<b <b class='f-red'>C</b>lass='f-red'>B</b>>,<b <b class='f-red'>C</b>lass='f-red'>B</b>,<b class='f-red'>C</b>,d,e
<<b <b class='f-re<b class='f-red'>D</b>'>C</b>lass='f-re<b class='f-red'>D</b>'>B</b> <b class='f-re<b class='f-red'>D</b>'>C</b>lass='f-re<b class='f-red'>D</b>'>A</<b <b class='f-re<b class='f-red'>D</b>'>C</b>lass='f-re<b class='f-red'>D</b>'>B</b>>,<b <b class='f-re<b class='f-red'>D</b>'>C</b>lass='f-re<b class='f-red'>D</b>'>B</b>,<b class='f-re<b class='f-red'>D</b>'>C</b>,<b class='f-red'>D</b>,e
<<b <b class='f-r<b class='f-red'>E</b><b class='f-r<b class='f-red'>E</b>d'>D</b>'>C</b>lass='f-r<b class='f-red'>E</b><b class='f-r<b class='f-red'>E</b>d'>D</b>'>B</b> <b class='f-r<b class='f-red'>E</b><b class='f-r<b class='f-red'>E</b>d'>D</b>'>C</b>lass='f-r<b class='f-red'>E</b><b class='f-r<b class='f-red'>E</b>d'>D</b>'>A</<b <b class='f-r<b class='f-red'>E</b><b class='f-r<b class='f-red'>E</b>d'>D</b>'>C</b>lass='f-r<b class='f-red'>E</b><b class='f-r<b class='f-red'>E</b>d'>D</b>'>B</b>>,<b <b class='f-r<b class='f-red'>E</b><b class='f-r<b class='f-red'>E</b>d'>D</b>'>C</b>lass='f-r<b class='f-red'>E</b><b class='f-r<b class='f-red'>E</b>d'>D</b>'>B</b>,<b class='f-r<b class='f-red'>E</b><b class='f-r<b class='f-red'>E</b>d'>D</b>'>C</b>,<b class='f-r<b class='f-red'>E</b>d'>D</b>,<b class='f-red'>E</b>
本文来自博客园,作者:孙龙-程序员,转载请注明原文链接:https://www.cnblogs.com/sunlong88/p/13360481.html