Match ISBN numbers





examples/regex/isbn.py
import re

strings = [
    '99921-58-10-7',
    '9971-5-0210-0',
    '960-425-059-0',
    '80-902734-1-6',
    '85-359-0277-5',
    '1-84356-028-3',
    '0-684-84328-5',
    '0-8044-2957-X',
    '0-85131-041-9',
    '0-943396-04-2',
    '0-9752298-0-X',

    '0-975229-1-X',
    '0-9752298-10-X',
    '0-9752298-0-Y',
    '910975229-0-X',
    '-------------',
    '0000000000000',
]
for isbn in strings:
    print(isbn)

    if (re.search(r'^[\dX-]{13}$', isbn)):
        print("match 1")

    if (re.search(r'^\d{1,5}-\d{1,7}-\d{1,5}-[\dX]$', isbn) and len(isbn) == 13):
        print("match 2")