Files
htwkalender/services/data-manager/service/functions/roomMapping.go
2024-08-17 18:10:46 +02:00

25 lines
720 B
Go

package functions
import (
"regexp"
"strings"
)
func MapRoom(room string) string {
// remove dots from room string
room = strings.ReplaceAll(room, ".", "")
// Regular expression pattern to match room identifiers
// The pattern looks for strings that start with two uppercase letters, optionally followed by an underscore,
// followed by 1 to 3 digits, and ending with "-[A-Z]"
re := regexp.MustCompile(`\b[A-ZÄÖÜ]{2}([_]+[A-ZÄÖÜ])?[0-9]{1,4}[a-zäöü]?-[A-ZÄÖÜ]\b`)
// Use the ReplaceAllStringFunc to process each match
result := re.ReplaceAllStringFunc(room, func(match string) string {
// Remove the last two characters (i.e., "-<letter>")
return match[:len(match)-2]
})
return result
}