可以使用正则表达式匹配斜杠字符 '/',判断某个字符串里是否包含斜杠。具体实现如下:

import re

string = 'This is a string with a / character.'
if re.search('/', string):
    print('The string contains a / character.')
else:
    print('The string does not contain a / character.')

在上述代码中,re.search() 函数会在字符串中查找与正则表达式匹配的内容,如果找到则返回匹配对象,否则返回 None。因此,如果字符串中包含斜杠字符,则 re.search() 函数会返回匹配对象,从而判断出字符串中包含斜杠。

Python 正则表达式判断字符串是否包含斜杠

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

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