Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "bufio"
- "bytes"
- "fmt"
- //"os"
- "regexp"
- "net"
- )
- func main() {
- re := regexp.MustCompile("(gopher){2}")
- //string
- mystring := "gophergopher"
- fmt.Println(re.MatchString(mystring))
- //byte array
- fmt.Println(re.Match([]byte(mystring)))
- //bytes.Buffer but needs to be put to []bytes or string?
- var a_buffer bytes.Buffer
- a_buffer.WriteString(mystring)
- fmt.Println(re.Match(a_buffer.Bytes()))
- conn, _ := net.Dial("tcp", "127.0.0.1:8081")
- // send to socket echo server
- fmt.Fprintf(conn, mystring+"\n")
- message, _ := bufio.NewReader(conn).ReadBytes('\n')
- fmt.Println(re.Match(message))
- fmt.Fprintf(conn, mystring+"\n")
- message2, _ := bufio.NewReader(conn).ReadString('\n')
- fmt.Println(re.MatchString(message2))
- }
- /**
- $ go run example.go
- true
- true
- true
- true
- true
- **/
Add Comment
Please, Sign In to add comment