[英]python regex: don't allow a specific character to repeat
I have a regex 我有一个正则表达式
^[a-z][a-z0-9\-]{6,10}[a-z0-9]$
Which matches the following rules: 符合以下规则:
it's re-used a lot in a module, always alongside some other rules and regexes 它在模块中经常重复使用,并且总是与其他一些规则和正则表达式一起使用
while writing out some unit tests, i noticed that it's always used in conjunction with another specific rule. 在编写一些单元测试时,我注意到它总是与另一条特定规则结合使用。
i can't wrap my head around integrating that rule into this one. 我无法将规则整合到这一规则中来。 i've tried a few dozen approaches with lookbehinds and lookaheads, but have had no luck on isolating to the specific character AND keeping the length requirement.
我已经尝试了数十种方法,具有后顾之忧和前瞻性,但在隔离特定字符并保持长度要求方面没有运气。
No repeating hyphen ^[az](?:[a-z0-9]|-(?!-)){6,10}[a-z0-9]$
没有重复的连字符
^[az](?:[a-z0-9]|-(?!-)){6,10}[a-z0-9]$
Explained 讲解
^ [a-z]
(?:
[a-z0-9] # alnum
| # or
- (?! - ) # hyphen if not followed by hyphen
){6,10}
[a-z0-9] $
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.