Created
April 3, 2023 18:15
-
-
Save rnek0/641f4acf56714d1e70470d03f30151e6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//"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