package main
import (
"fmt"
"regexp"
)
func main() {
line := "2022/11/25 19:32 <DIR> catalog 2022/11/25 19:32 <DIR> catalog"
reg := regexp.MustCompile(`([\d/]+)\s+(\d+:\d+)\s+(<DIR>)\s+(\w+)`)
if reg == nil {
panic("命令行解析失败")
}
// 符合正则匹配的,可能有多条
r := reg.FindAllStringSubmatch(line, -1)
for _, one := range r {
fmt.Printf("解析结果为 %v", one)
for _, v := range one {
fmt.Println(v)
}
}
}
python 正则
import re
text = "http://178.162.209.4:3000"
prog = re.compile("([https:]+)\/\/([\d+\.:]*)")
a = prog.search(text)
# 返回数组
print(a.groups()[1])