你可以使用以下的正则表达式来检查一个字符串是否包含连续的特殊字符:

import re

def check_special_characters(strings):
    for string in strings:
        if not re.search(r"[^\w\s]", string):
            return True
    return False

# 测试
strings1 = ["Hello", "World!", "123", "abc"]
print(check_special_characters(strings1))  # True

strings2 = ["Hello", "Wor!ld", "123", "abc"]
print(check_special_characters(strings2))  # False

在这个例子中,我们使用re.search函数和正则表达式[^\w\s]来匹配任何非字母、非数字、非下划线和非空格的字符。如果字符串中包含连续的特殊字符,则返回False;如果所有字符串都不包含连续的特殊字符,则返回True

请帮我写一个验证一个字符串数组里面的字符串是否包含连续的特殊字符的正则如果这个字符串数组里面的字符串没有包含连续的特殊字符就返回true否则为false

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

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