Does anyone have an idea on how to convert the following commands into one or fewer commands?
variable = re.search("[a-zA-Z0-9]+[a-zA-Z0-9\-' ]+[a-zA-Z0-9]+", variable).group(0)
variable = re.sub(" {2,}", " ", variable)开发者_开发问答
variable = re.sub("'{2,}", "'", variable)
variable = re.sub("\-{2,}", "-", variable)
Kind Regards,
Marian
This is a start:
variable = re.search("[a-zA-Z0-9]+[a-zA-Z0-9\-' ]+[a-zA-Z0-9]+", variable).group(0)
variable = re.sub("([ '\-])\\1+", "\\1", variable)
精彩评论