我试过这个正则表达式:
^\w{5}\.(exe)$
应该匹配
5 个字母后跟 .exe,例如:
abcde.exe
regra.exe
它不适用于“samba 投票文件”
我的错误在哪里?
提前致谢。
我试过这个正则表达式:
^\w{5}\.(exe)$
应该匹配
5 个字母后跟 .exe,例如:
abcde.exe
regra.exe
它不适用于“samba 投票文件”
我的错误在哪里?
提前致谢。
Your regex will match 12345.exe and even _____.exe, which is not your states intention.
To match 5 (lowercase) letters then ".exe":
^[a-z]{5}\.exe$
^(\w{5})(?=.exe$)

它匹配第一个字母并将它们放入捕获组,如果其后跟一个 .exe 但根本不捕获 .exe!
这也将起作用:)
^(\w{5}).exe$

^ 表示行的开始\w表示字母、数字和下划线(同[_a-zA-Z0-9]){5}正好代表 5 个字符$ 是行尾不需要括号.exe(尽管它们不应该导致任何错误);这应该足够了:
^\w{5}\.exe$
python中的示例:
import re
In[1]: re.search('^\w{5}\.exe$', 'regra.exe')
Out[1]: <_sre.SRE_Match at 0x101f1fb90>
In [2]: re.search('^\w{5}\.exe$', 'abcdeas.exe')
Out[2]: None