首次提交:初始化项目代码
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
var namedRegex = regexp.MustCompile(`姓名:(?P<name>[\p{Han}a-zA-Z0-9]+),城市:(?P<city>[\p{Han}a-zA-Z0-9]+)`)
|
||||
|
||||
func main() {
|
||||
text := "姓名:孙三苗,城市:北京"
|
||||
match := namedRegex.FindStringSubmatch(text)
|
||||
for i, name := range namedRegex.SubexpNames() {
|
||||
if i > 0 && name != "" {
|
||||
fmt.Printf("%s:%s\n", name, match[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user