基于Python的货币识别技术实现
warning:
这篇文章距离上次修改已过193天,其中的内容可能已经有所变动。
import re
def identify_currency(text):
# 正则表达式匹配货币符号
currency_pattern = re.compile(r'\p{Sc}')
matches = currency_pattern.findall(text)
return matches
# 示例使用
text_example = "今天的收入是 100 美元和 200 英镑,以及 500 日元。"
currencies = identify_currency(text_example)
print(currencies) # 输出:['$', '£', '¥']
这段代码使用了Python的正则表达式模块re
来匹配文本中的货币符号。\p{Sc}
是Unicode正则表达式的一个特殊标记,它匹配所有的货币符号。然后使用findall
方法找出所有的货币符号并返回一个列表。
评论已关闭