mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2025-07-16 17:48:49 +02:00
25 lines
720 B
Go
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
|
|
}
|