import re
texts = ['ISBN-13: 978 1 4310 0862 9',
	'ISBN: 9781431008629',
	'ISBN9781431008629',
	'ISBN 9-78-1431-008-629',
	'ISBN: 9781431008629 more text of the number',
	'isbn : 9781431008629']
rx = re.compile(r'ISBN(?:-13)?\D*(\d(?:\W*\d){12})', re.I)
for text in texts:
	m = rx.search(text)
	if m:
		print(text, '=> ISBN:', ''.join([d for d in m.group(1) if d.isdigit()]))
