-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
72 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
@File : text_util.py | ||
@Date : 2023-05-30 | ||
""" | ||
import re | ||
|
||
|
||
def has_chinese(text: str) -> bool: | ||
""" | ||
判断是否包含中文 | ||
:param text: | ||
:return: | ||
""" | ||
result = re.match("[\u4e00-\u9fa5]+", text) | ||
return True if result else False | ||
|
||
|
||
def extract_chinese(text: str) -> str: | ||
""" | ||
提取包含的中文 | ||
:param text: | ||
:return: | ||
""" | ||
result = re.match("[\u4e00-\u9fa5]+", text) | ||
if result: | ||
return result.group(0) | ||
else: | ||
return "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
@File : test_text_util.py | ||
@Date : 2023-05-30 | ||
""" | ||
from domain_admin.utils import text_util | ||
|
||
|
||
def test_has_chinese(): | ||
assert text_util.has_chinese("I love you") is False | ||
assert text_util.has_chinese("我喜欢你") is True | ||
assert text_util.has_chinese("我 love 你") is True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters