#!/usr/bin/env python import re change_message="removed segv bug #54454, #45454, #78677" bug_strings=re.compile("#[1-9][0-9]+").findall(change_message) if bug_strings: for bug in bug_strings: print bug[1:]