我想找到其中没有.
个字符的字符串,在字符串的末尾可以 Select 出现这个字符.
我像那样搜索了一些提示,但没有解决我的问题.
^(?!\.)(?!.*\.$)(?!.*\.\.)[a-zA-Z0-9_.]+$
(?!\.) - don't allow . at start
(?!.*\.\.) - don't allow 2 consecutive dots
(?!.*\.$) - don't allow . at end
我试着用
str_l = ["aaa.bbb.","aaa.","aaa"]
for str1 in str_l:
res1 = re.search(r'(.*?!.*$)', str1) #if .not in string, return True
res2 = re.search(r'(?<!(.).$)',str1) # if . only appear at the end of string, return True, but not solved
print(res1,res2)
我想将res1
和res2
组合成一个正则表达式,字符串的结果类似于False, True, True
.