@@ -12,7 +12,7 @@ def search_string(pattern: str, text: str) -> re.Match[str] | None:
12
12
:return:
13
13
"""
14
14
if not pattern or not text :
15
- return
15
+ return None
16
16
17
17
result = re .search (pattern , text )
18
18
return result
@@ -27,7 +27,7 @@ def match_string(pattern: str, text: str) -> re.Match[str] | None:
27
27
:return:
28
28
"""
29
29
if not pattern or not text :
30
- return
30
+ return None
31
31
32
32
result = re .match (pattern , text )
33
33
return result
@@ -41,7 +41,7 @@ def is_phone(number: str) -> re.Match[str] | None:
41
41
:return:
42
42
"""
43
43
if not number :
44
- return
44
+ return None
45
45
46
46
phone_pattern = r'^1[3-9]\d{9}$'
47
47
return match_string (phone_pattern , number )
@@ -55,31 +55,7 @@ def is_git_url(url: str) -> re.Match[str] | None:
55
55
:return:
56
56
"""
57
57
if not url :
58
- return
58
+ return None
59
59
60
60
git_pattern = r'^(?!(git\+ssh|ssh)://|git@)(?P<scheme>git|https?|file)://(?P<host>[^/]*)(?P<path>(?:/[^/]*)*/)(?P<repo>[^/]+?)(?:\.git)?$'
61
61
return match_string (git_pattern , url )
62
-
63
-
64
- if __name__ == '__main__' :
65
- test_urls = [
66
- # 合法协议地址 (git/http/https/file)
67
- 'git://github.com/user/repo.git' ,
68
- 'git://gitlab.com/group/project.git' ,
69
- 'git://example.com:8080/custom/repo.git' , # 带端口
70
- 'http://github.com/user/repo.git' ,
71
- 'https://gitlab.com/group/project.git' ,
72
- 'http://example.com:8080/custom/repo.git' ,
73
- 'file:///path/to/local/repo' , # Unix路径
74
- 'file:///C:/Projects/repo' , # Windows路径
75
- 'https://github.com/user/repo.with.dots' , # 特殊字符
76
- # 无效协议地址 (应被正则排除)
77
- 'git://host.com' , # 最小格式(无路径)
78
- '[email protected] :user/repo.git' ,
# SSH格式
79
- 'ssh://[email protected] /user/repo.git' ,
80
- 'git+ssh://[email protected] /user/repo.git' ,
81
- 'github.com/user/repo.git' , # 无协议
82
- 'ftp://example.com/repo.git' , # 非法协议
83
- ]
84
- for url in test_urls :
85
- print (bool (is_git_url (url )))
0 commit comments