Python - 判断字符串是英语句子(大小写字母数字符号)

Posted SpikeKing

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python - 判断字符串是英语句子(大小写字母数字符号)相关的知识,希望对你有一定的参考价值。

A-Z是大写、a-z是小写、0-9是数字,其他的是标点符号,注意添加空格,还有单引号的转义,同时,也可以添加中文的标点符号“,。”等。

源码如下:

@staticmethod
def check_en_str(string):
    import re
    pattern = re.compile('^[A-Za-z0-9.,:;!?()_*"\\' ]+$')
    if pattern.fullmatch(string):
        return True
    else:
        return False

参考:

以上是关于Python - 判断字符串是英语句子(大小写字母数字符号)的主要内容,如果未能解决你的问题,请参考以下文章