34 lines
702 B
Go
34 lines
702 B
Go
package wordlepattern
|
|
|
|
import (
|
|
"regexp"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
// Pattern matches "Wordle XXXX Y/6" format
|
|
var pattern = regexp.MustCompile(`(?i)Wordle\s+(\d+)\s+([X1-6])/6`)
|
|
|
|
// Match represents a matched Wordle score
|
|
type Match struct {
|
|
PuzzleNumber int
|
|
Score string
|
|
}
|
|
|
|
// Find searches for a Wordle pattern in the given text
|
|
// Returns the match and a boolean indicating if a match was found
|
|
func Find(text string) (*Match, bool) {
|
|
matches := pattern.FindStringSubmatch(text)
|
|
if matches == nil {
|
|
return nil, false
|
|
}
|
|
|
|
puzzleNumber, _ := strconv.Atoi(matches[1])
|
|
score := strings.ToUpper(matches[2])
|
|
|
|
return &Match{
|
|
PuzzleNumber: puzzleNumber,
|
|
Score: score,
|
|
}, true
|
|
}
|