How to match any single character in a string using regular expression with Go

1 Answer

0 votes
package main

import (
    "fmt"
    "regexp"
)

func main() {
    pattern := regexp.MustCompile(`b.d`)

    testStrings := []string{
        "bud",  // returns true (1)
        "bid",  // returns true (1)
        "bed",  // returns true (1)
        "b d",  // returns true (1)
        "bat",  // returns false (0)
        "bd",   // returns false (0)
        "bead", // returns false (0)
    }

    for _, str := range testStrings {
        match := pattern.MatchString(str)
        fmt.Println(match)
    }
}



/*
run:

true
true
true
true
false
false
false

*/

 



answered Feb 15, 2025 by avibootz
...