Guest User

Untitled

a guest
Nov 23rd, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "bufio"
  5. "bytes"
  6. "fmt"
  7. //"os"
  8. "regexp"
  9. "net"
  10. )
  11.  
  12. func main() {
  13. re := regexp.MustCompile("(gopher){2}")
  14.  
  15. //string
  16. mystring := "gophergopher"
  17. fmt.Println(re.MatchString(mystring))
  18.  
  19. //byte array
  20. fmt.Println(re.Match([]byte(mystring)))
  21.  
  22. //bytes.Buffer but needs to be put to []bytes or string?
  23. var a_buffer bytes.Buffer
  24. a_buffer.WriteString(mystring)
  25. fmt.Println(re.Match(a_buffer.Bytes()))
  26.  
  27. conn, _ := net.Dial("tcp", "127.0.0.1:8081")
  28. // send to socket echo server
  29. fmt.Fprintf(conn, mystring+"\n")
  30. message, _ := bufio.NewReader(conn).ReadBytes('\n')
  31. fmt.Println(re.Match(message))
  32.  
  33. fmt.Fprintf(conn, mystring+"\n")
  34. message2, _ := bufio.NewReader(conn).ReadString('\n')
  35. fmt.Println(re.MatchString(message2))
  36.  
  37. }
  38. /**
  39. $ go run example.go
  40. true
  41. true
  42. true
  43. true
  44. true
  45. **/
Add Comment
Please, Sign In to add comment