refactor(go)!: 分离练习区与独立项目区
- 将现有练习及 module 文件迁移至 go/practice,保持代码和依赖不变 - 新增 go/projects 项目区说明,更新目录约定与开发命令 BREAKING CHANGE: Go 练习命令需改在 go/practice 目录下执行
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package regularmatch
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestChineseRegExp(t *testing.T) {
|
||||
reg, err := regexp.Compile("[\u4e00-\u9fa5]")
|
||||
if err != nil {
|
||||
t.Errorf("Failed to compile regex: %v", err)
|
||||
}
|
||||
matchStrSlice := reg.FindAllString("hello 世界", -1)
|
||||
|
||||
if len(matchStrSlice) != 2 {
|
||||
t.Errorf("Expected 2 matches, got %d", len(matchStrSlice))
|
||||
}
|
||||
if matchStrSlice[0] != "世" || matchStrSlice[1] != "界" {
|
||||
t.Errorf("Expected [世, 界], got %v", matchStrSlice)
|
||||
}
|
||||
}
|
||||
|
||||
func TestChinaMobile(t *testing.T) {
|
||||
reg, err := regexp.Compile(`^1(3\d|4[5-9]|5[0-35-9]|6[2567]|7[0-8]|8\d|9[0-35-9])\d{8}$`)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to compile regex: %v", err)
|
||||
}
|
||||
// matchStrSlice := reg.FindAllString("123-12345678 1234-12345678", -1)
|
||||
// if len(matchStrSlice) != 2 {
|
||||
// t.Errorf("Expected 2 matches, got %d", len(matchStrSlice))
|
||||
// }
|
||||
matchStrSlice := reg.FindAllString("17623862704", -1)
|
||||
t.Log(matchStrSlice[0])
|
||||
}
|
||||
Reference in New Issue
Block a user