util.go 522 B

12345678910111213141516171819202122232425262728
  1. package local_objs
  2. import "regexp"
  3. func GetObjFromText(text string) []string {
  4. rule := "img src=\".*?\""
  5. reg, _ := regexp.Compile(rule)
  6. result := reg.FindAllStringSubmatch(text, -1)
  7. if len(result) == 0 {
  8. return []string{}
  9. }
  10. ret := []string{}
  11. key := "img src=\""
  12. keyLength := len(key)
  13. for _, array := range result {
  14. if len(array) == 0 {
  15. continue
  16. }
  17. str := array[0]
  18. if len(str) < keyLength+1 {
  19. continue
  20. }
  21. str = str[keyLength:]
  22. str = str[:len(str)-1]
  23. ret = append(ret, str)
  24. }
  25. return ret
  26. }