开发者

Regex + Python - Converting multiple commands into one or fewer commands

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)
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜