.re:(网上摘)
import re pattern = re.compile("forum\/(\d*)\/topic\/(\d*)") res = pattern.search('forum/135/topic/794150').groups() print res[0],res[1]