我需要一个正则表达式匹配api路径与以下规则
“/”后面必须跟一个以小写开头的单词,但以后可以是大写
x = ["/word/worD/sdfsfsd","/fsdfsdf","/","/{sfsdf",'/','/_','/{','/{"type":"tnt"}',"/allGear{Exe","/Grear"]
import re
pattern = re.compile("(/[a-z][a-zA-Z]+)+")
for y in x:
print (pattern.match(y))
因此在本例中,只有前两个元素必须生成匹配。你知道吗
使用以下方法:
输出:
我想这应该适合你。但是,正如在评论中所说的,我认为根据你的描述
/allGear{Exe
也应该包括在内。我给出的代码也返回了这个结果相关问题 更多 >
编程相关推荐