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',
    '3-3-3-X',
]
for isbn in strings:
    print(isbn)

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

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