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)
精彩评论