mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-21 12:52:26 +00:00
refactor: 优化代码结构和可读性 feat: 添加http_limit模块实现请求限制功能 fix: 修复异步任务中使用time.sleep的问题 chore: 更新依赖项并添加pytest测试框架 docs: 更新项目描述信息 perf: 优化Redis序列化方式使用JSON替代pickle test: 添加测试相关配置和依赖
72 lines
1.5 KiB
Python
72 lines
1.5 KiB
Python
import re
|
|
|
|
|
|
def search_string(pattern: str, text: str) -> re.Match[str] | None:
|
|
"""
|
|
全字段正则匹配
|
|
|
|
参数:
|
|
- pattern (str): 正则表达式模式。
|
|
- text (str): 待匹配的文本。
|
|
|
|
返回:
|
|
- re.Match[str] | None: 匹配结果。
|
|
"""
|
|
if not pattern or not text:
|
|
return None
|
|
|
|
result = re.search(pattern, text)
|
|
return result
|
|
|
|
|
|
def match_string(pattern: str, text: str) -> re.Match[str] | None:
|
|
"""
|
|
从字段开头正则匹配
|
|
|
|
参数:
|
|
- pattern (str): 正则表达式模式。
|
|
- text (str): 待匹配的文本。
|
|
|
|
返回:
|
|
- re.Match[str] | None: 匹配结果。
|
|
"""
|
|
if not pattern or not text:
|
|
return None
|
|
|
|
result = re.match(pattern, text)
|
|
return result
|
|
|
|
|
|
def is_phone(number: str) -> re.Match[str] | None:
|
|
"""
|
|
检查手机号码格式
|
|
|
|
参数:
|
|
- number (str): 待检查的手机号码。
|
|
|
|
返回:
|
|
- re.Match[str] | None: 匹配结果。
|
|
"""
|
|
if not number:
|
|
return None
|
|
|
|
phone_pattern = r"^1[3-9]\d{9}$"
|
|
return match_string(phone_pattern, number)
|
|
|
|
|
|
def is_git_url(url: str) -> re.Match[str] | None:
|
|
"""
|
|
检查 git URL 格式
|
|
|
|
参数:
|
|
- url (str): 待检查的 URL。
|
|
|
|
返回:
|
|
- re.Match[str] | None: 匹配结果。
|
|
"""
|
|
if not url:
|
|
return None
|
|
|
|
git_pattern = r"^(?!(git\+ssh|ssh)://|git@)(?P<scheme>git|https?|file)://(?P<host>[^/]*)(?P<path>(?:/[^/]*)*/)(?P<repo>[^/]+?)(?:\.git)?$"
|
|
return match_string(git_pattern, url)
|