python - Which regular expression to use to exclude certain ending in string? -
i have 2 slugs, capture one. struggle exclude second has added # plus text.
here 2 slugs:
slugs = ['/sub/12345678', '/sub/12345678#is'] and here tried python's re:
cleaned_slugs = [] in slugs: slug_check = re.match('/sub/[0-9]{8}[^#]', i).group(0) cleaned_slug.append(slug_check) when try out regex on pythex, selects first slug.
what wrong?
btw: know for loop not elegant way. appreciate shorter answer…
if want sub included , 1 without "#":
slugs = ['/sub/12345678', '/sub/12345678#is'] cleaned_slugs = [] in slugs: patt= re.search(r'/sub/[0-9]{8}$', i) if patt: cleaned_slugs.append(patt.group()) cleaned_slugs ['/sub/12345678']
Comments
Post a Comment