emailextract.go
von paedubucher- SNIPPET_DESC:
- Extraktion von Informationen aus E-Mail-Adressen
- SNIPPET_CREATION_TIME:
- 19.06.2022 17:27:07
- SNIPPET_PRUNE_TIME:
- Unendlich
- SNIPPET_TEXT:
-
- package dfdegoregexp
- import (
- "fmt"
- "regexp"
- )
- var (
- // TODO: This regexp must be written. Figure out group names according to switch/case below.
- r = ``
- p = regexp.MustCompile(r)
- )
- type emailInfo struct {
- first, last, company string
- year int
- }
- func (e emailInfo) String() string {
- if e.first == "" || e.company == "" {
- return ""
- }
- var y int
- if e.year != 0 {
- if e.year >= 100 {
- y = e.year
- } else {
- y = 1900 + e.year
- }
- }
- if e.last != "" && y != 0 {
- return fmt.Sprintf("%s %s, *%d, %s", e.first, e.last, y, e.company)
- }
- if e.last != "" && y == 0 {
- return fmt.Sprintf("%s %s, %s", e.first, e.last, e.company)
- }
- if e.last == "" && y == 0 {
- return fmt.Sprintf("%s, %s", e.first, e.company)
- }
- return ""
- }
- func Extract(email string) string {
- matches := p.FindStringSubmatch(email)
- if len(matches) == 0 {
- return ""
- }
- var ei emailInfo
- for i, name := range p.SubexpNames() {
- switch name {
- case "first":
- // TODO
- case "last":
- // TODO
- case "year":
- // TODO
- case "comp":
- // TODO
- }
- }
- return ei.String()
- }
Quellcode
Hier kannst du den Code kopieren und ihn in deinen bevorzugten Editor einfügen. PASTEBIN_DOWNLOAD_SNIPPET_EXPLAIN