First commit
This commit is contained in:
33
pkg/wordlepattern/pattern.go
Normal file
33
pkg/wordlepattern/pattern.go
Normal file
@ -0,0 +1,33 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user