要判断一个字符串是否含有中文逗号,可以使用正则表达式来实现。

正则表达式:'[,]'

解释:

  • '[,]':表示匹配一个字符,这个字符是中文逗号的Unicode编码。

示例代码:

import re

def has_chinese_comma(string):
    pattern = re.compile('[,]')
    match = pattern.search(string)
    if match:
        return True
    else:
        return False

# 测试
print(has_chinese_comma('Hello, 你好')) # True
print(has_chinese_comma('Hello,你好')) # True
print(has_chinese_comma('Hello, Hello')) # False
Python 正则表达式判断字符串是否包含中文逗号

原文地址: https://www.cveoy.top/t/topic/pZm4 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录