开发者

regexp matching slug

开发者 https://www.devze.com 2023-04-08 12:29 出处:网络
Please help with slug regexp. I would appreciate if the code will be given in python. Conditions: 1 #valid

Please help with slug regexp.

I would appreciate if the code will be given in python.

Conditions:

1 #valid 
1-1 #valid
1-1-1 #valid (infinite \d-\d)
开发者_StackOverflow中文版
1- #invalid
-1 #invalid
-1- #invalid

*NOTE 1 = \d


I would write it this way:

compiled = re.compile(r'\d(?:-\d)*$')
result = compiled.match(string_to_parse)


How about:

re.match(r'\d(?:-\d)*$', s)
0

精彩评论

暂无评论...
验证码 换一张
取 消