get_suffix.go
· 200 B · Go
原始檔案
func getSuffix(fileName string) string {
regex := `\.[^\.]*$`
re, _ := regexp.Compile(regex)
foundSuffix := re.FindString(fileName)
if len(foundSuffix) <= 5 {
return foundSuffix
}
return ""
}
| 1 | func getSuffix(fileName string) string { |
| 2 | regex := `\.[^\.]*$` |
| 3 | re, _ := regexp.Compile(regex) |
| 4 | foundSuffix := re.FindString(fileName) |
| 5 | if len(foundSuffix) <= 5 { |
| 6 | return foundSuffix |
| 7 | } |
| 8 | return "" |
| 9 | } |
| 10 |
get_suffix.py
· 157 B · Python
原始檔案
def get_suffix(name):
m = re.search(r"\.[^\.]*$", name)
if m.group(0) and len(m.group(0)) <= 5:
return m.group(0)
else:
return ""
| 1 | def get_suffix(name): |
| 2 | m = re.search(r"\.[^\.]*$", name) |
| 3 | if m.group(0) and len(m.group(0)) <= 5: |
| 4 | return m.group(0) |
| 5 | else: |
| 6 | return "" |