Skip to content

Instantly share code, notes, and snippets.

@rnek0
Created April 3, 2023 18:15
Show Gist options
  • Save rnek0/641f4acf56714d1e70470d03f30151e6 to your computer and use it in GitHub Desktop.
Save rnek0/641f4acf56714d1e70470d03f30151e6 to your computer and use it in GitHub Desktop.
//"Confirmer Y/y/Yes/yes ?"
package main
import(
"bufio"
"fmt"
"log"
"os"
"regexp"
"strconv"
"strings"
)
func askForConfirmation() bool {
r := bufio.NewReader(os.Stdin)
response, err := r.ReadString('\n')
if err != nil {
log.Panic(err)
}
response = strings.ReplaceAll(response, "\n", "")
response = strings.ReplaceAll(response, "\r", "")
yes := regexp.MustCompile("^[Y|y]$|^[Y|y]es$")
no := regexp.MustCompile("^[N|n]$|^[N|n]o$")
match := yes.MatchString(response) && !no.MatchString(response)
return match
}
func main(){
fmt.Println("Confirmer Y/y/Yes/yes ?")
fn3 := askForConfirmation()
fmt.Println(fn3)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment