Regular expressions (English regular expressions, abbr. RegExp, RegEx, jarg. Regekspy or regex) - a system of syntactic analysis of text fragments on a formalized pattern, based on the system of writing patterns for search. The pattern (English pattern), which sets the search rule, is also sometimes called in Russian “pattern”, “mask”.
Wikipedia
^(?:ISBN(?:-1[03])?:? )?(?=[-0-9 ]{17}$|[-0-9X ]{13}$|[0-9X]{10}$)(?:97[89][- ]?)?[0-9]{1,5}[- ]?(?:[0-9]+[- ]?){2}[0-9X]$
really works. I will check in the Espresso text editor.
# -*- coding: utf-8 -*- # file: isbn_check.py import re import sys # ISBN-10 ISBN-13 regex = re . compile ( "^(?:ISBN(?:-1[03])?:? )?(?=[-0-9 ]{17}$|[-0-9X ]{13}$|[0-9X]{10}$)(?:97[89][- ]?)?[0-9]{1,5}[- ]?(?:[0-9]+[- ]?){2}[0-9X]$" ) subject = sys . argv [ 1 ] if regex. search ( subject ) : # , ISBN cbuf = re . sub ( "[^0-9X]" , "" , subject ) # chars = list ( ) # for item in cbuf [ : ] : chars. append ( item ) # chars last last = chars. pop ( ) if len ( chars ) == 9 : # ISBN-10 val = sum ( ( x + 2 ) * int ( y ) for x, y in enumerate ( reversed ( chars ) ) ) check = 11 - ( val % 11 ) if check == 10 : check = "X" elif check == 11 : check = "0" else : # ISBN-13 val = sum ( ( x % 2 * 2 + 1 ) * int ( y ) for x, y in enumerate ( chars ) ) check = 10 - ( val % 10 ) if check == 10 : check = "0" if ( str ( check ) == last ) : print u " ISBN" else : print u " ISBN" else : print u " ISBN"
# -*- coding: utf-8 -*- # file: isbn_check.py import re import sys # ISBN-10 ISBN-13 regex = re . compile ( "^(?:ISBN(?:-1[03])?:? )?(?=[-0-9 ]{17}$|[-0-9X ]{13}$|[0-9X]{10}$)(?:97[89][- ]?)?[0-9]{1,5}[- ]?(?:[0-9]+[- ]?){2}[0-9X]$" ) subject = sys . argv [ 1 ] if regex. search ( subject ) : # , ISBN cbuf = re . sub ( "[^0-9X]" , "" , subject ) # chars = list ( ) # for item in cbuf [ : ] : chars. append ( item ) # chars last last = chars. pop ( ) if len ( chars ) == 9 : # ISBN-10 val = sum ( ( x + 2 ) * int ( y ) for x, y in enumerate ( reversed ( chars ) ) ) check = 11 - ( val % 11 ) if check == 10 : check = "X" elif check == 11 : check = "0" else : # ISBN-13 val = sum ( ( x % 2 * 2 + 1 ) * int ( y ) for x, y in enumerate ( chars ) ) check = 10 - ( val % 10 ) if check == 10 : check = "0" if ( str ( check ) == last ) : print u " ISBN" else : print u " ISBN" else : print u " ISBN"
# -*- coding: utf-8 -*- # file: isbn_check.py import re import sys # ISBN-10 ISBN-13 regex = re . compile ( "^(?:ISBN(?:-1[03])?:? )?(?=[-0-9 ]{17}$|[-0-9X ]{13}$|[0-9X]{10}$)(?:97[89][- ]?)?[0-9]{1,5}[- ]?(?:[0-9]+[- ]?){2}[0-9X]$" ) subject = sys . argv [ 1 ] if regex. search ( subject ) : # , ISBN cbuf = re . sub ( "[^0-9X]" , "" , subject ) # chars = list ( ) # for item in cbuf [ : ] : chars. append ( item ) # chars last last = chars. pop ( ) if len ( chars ) == 9 : # ISBN-10 val = sum ( ( x + 2 ) * int ( y ) for x, y in enumerate ( reversed ( chars ) ) ) check = 11 - ( val % 11 ) if check == 10 : check = "X" elif check == 11 : check = "0" else : # ISBN-13 val = sum ( ( x % 2 * 2 + 1 ) * int ( y ) for x, y in enumerate ( chars ) ) check = 10 - ( val % 10 ) if check == 10 : check = "0" if ( str ( check ) == last ) : print u " ISBN" else : print u " ISBN" else : print u " ISBN"
# -*- coding: utf-8 -*- # file: isbn_check.py import re import sys # ISBN-10 ISBN-13 regex = re . compile ( "^(?:ISBN(?:-1[03])?:? )?(?=[-0-9 ]{17}$|[-0-9X ]{13}$|[0-9X]{10}$)(?:97[89][- ]?)?[0-9]{1,5}[- ]?(?:[0-9]+[- ]?){2}[0-9X]$" ) subject = sys . argv [ 1 ] if regex. search ( subject ) : # , ISBN cbuf = re . sub ( "[^0-9X]" , "" , subject ) # chars = list ( ) # for item in cbuf [ : ] : chars. append ( item ) # chars last last = chars. pop ( ) if len ( chars ) == 9 : # ISBN-10 val = sum ( ( x + 2 ) * int ( y ) for x, y in enumerate ( reversed ( chars ) ) ) check = 11 - ( val % 11 ) if check == 10 : check = "X" elif check == 11 : check = "0" else : # ISBN-13 val = sum ( ( x % 2 * 2 + 1 ) * int ( y ) for x, y in enumerate ( chars ) ) check = 10 - ( val % 10 ) if check == 10 : check = "0" if ( str ( check ) == last ) : print u " ISBN" else : print u " ISBN" else : print u " ISBN"
# -*- coding: utf-8 -*- # file: isbn_check.py import re import sys # ISBN-10 ISBN-13 regex = re . compile ( "^(?:ISBN(?:-1[03])?:? )?(?=[-0-9 ]{17}$|[-0-9X ]{13}$|[0-9X]{10}$)(?:97[89][- ]?)?[0-9]{1,5}[- ]?(?:[0-9]+[- ]?){2}[0-9X]$" ) subject = sys . argv [ 1 ] if regex. search ( subject ) : # , ISBN cbuf = re . sub ( "[^0-9X]" , "" , subject ) # chars = list ( ) # for item in cbuf [ : ] : chars. append ( item ) # chars last last = chars. pop ( ) if len ( chars ) == 9 : # ISBN-10 val = sum ( ( x + 2 ) * int ( y ) for x, y in enumerate ( reversed ( chars ) ) ) check = 11 - ( val % 11 ) if check == 10 : check = "X" elif check == 11 : check = "0" else : # ISBN-13 val = sum ( ( x % 2 * 2 + 1 ) * int ( y ) for x, y in enumerate ( chars ) ) check = 10 - ( val % 10 ) if check == 10 : check = "0" if ( str ( check ) == last ) : print u " ISBN" else : print u " ISBN" else : print u " ISBN"
# -*- coding: utf-8 -*- # file: isbn_check.py import re import sys # ISBN-10 ISBN-13 regex = re . compile ( "^(?:ISBN(?:-1[03])?:? )?(?=[-0-9 ]{17}$|[-0-9X ]{13}$|[0-9X]{10}$)(?:97[89][- ]?)?[0-9]{1,5}[- ]?(?:[0-9]+[- ]?){2}[0-9X]$" ) subject = sys . argv [ 1 ] if regex. search ( subject ) : # , ISBN cbuf = re . sub ( "[^0-9X]" , "" , subject ) # chars = list ( ) # for item in cbuf [ : ] : chars. append ( item ) # chars last last = chars. pop ( ) if len ( chars ) == 9 : # ISBN-10 val = sum ( ( x + 2 ) * int ( y ) for x, y in enumerate ( reversed ( chars ) ) ) check = 11 - ( val % 11 ) if check == 10 : check = "X" elif check == 11 : check = "0" else : # ISBN-13 val = sum ( ( x % 2 * 2 + 1 ) * int ( y ) for x, y in enumerate ( chars ) ) check = 10 - ( val % 10 ) if check == 10 : check = "0" if ( str ( check ) == last ) : print u " ISBN" else : print u " ISBN" else : print u " ISBN"
# -*- coding: utf-8 -*- # file: isbn_check.py import re import sys # ISBN-10 ISBN-13 regex = re . compile ( "^(?:ISBN(?:-1[03])?:? )?(?=[-0-9 ]{17}$|[-0-9X ]{13}$|[0-9X]{10}$)(?:97[89][- ]?)?[0-9]{1,5}[- ]?(?:[0-9]+[- ]?){2}[0-9X]$" ) subject = sys . argv [ 1 ] if regex. search ( subject ) : # , ISBN cbuf = re . sub ( "[^0-9X]" , "" , subject ) # chars = list ( ) # for item in cbuf [ : ] : chars. append ( item ) # chars last last = chars. pop ( ) if len ( chars ) == 9 : # ISBN-10 val = sum ( ( x + 2 ) * int ( y ) for x, y in enumerate ( reversed ( chars ) ) ) check = 11 - ( val % 11 ) if check == 10 : check = "X" elif check == 11 : check = "0" else : # ISBN-13 val = sum ( ( x % 2 * 2 + 1 ) * int ( y ) for x, y in enumerate ( chars ) ) check = 10 - ( val % 10 ) if check == 10 : check = "0" if ( str ( check ) == last ) : print u " ISBN" else : print u " ISBN" else : print u " ISBN"
# -*- coding: utf-8 -*- # file: isbn_check.py import re import sys # ISBN-10 ISBN-13 regex = re . compile ( "^(?:ISBN(?:-1[03])?:? )?(?=[-0-9 ]{17}$|[-0-9X ]{13}$|[0-9X]{10}$)(?:97[89][- ]?)?[0-9]{1,5}[- ]?(?:[0-9]+[- ]?){2}[0-9X]$" ) subject = sys . argv [ 1 ] if regex. search ( subject ) : # , ISBN cbuf = re . sub ( "[^0-9X]" , "" , subject ) # chars = list ( ) # for item in cbuf [ : ] : chars. append ( item ) # chars last last = chars. pop ( ) if len ( chars ) == 9 : # ISBN-10 val = sum ( ( x + 2 ) * int ( y ) for x, y in enumerate ( reversed ( chars ) ) ) check = 11 - ( val % 11 ) if check == 10 : check = "X" elif check == 11 : check = "0" else : # ISBN-13 val = sum ( ( x % 2 * 2 + 1 ) * int ( y ) for x, y in enumerate ( chars ) ) check = 10 - ( val % 10 ) if check == 10 : check = "0" if ( str ( check ) == last ) : print u " ISBN" else : print u " ISBN" else : print u " ISBN"
# -*- coding: utf-8 -*- # file: isbn_check.py import re import sys # ISBN-10 ISBN-13 regex = re . compile ( "^(?:ISBN(?:-1[03])?:? )?(?=[-0-9 ]{17}$|[-0-9X ]{13}$|[0-9X]{10}$)(?:97[89][- ]?)?[0-9]{1,5}[- ]?(?:[0-9]+[- ]?){2}[0-9X]$" ) subject = sys . argv [ 1 ] if regex. search ( subject ) : # , ISBN cbuf = re . sub ( "[^0-9X]" , "" , subject ) # chars = list ( ) # for item in cbuf [ : ] : chars. append ( item ) # chars last last = chars. pop ( ) if len ( chars ) == 9 : # ISBN-10 val = sum ( ( x + 2 ) * int ( y ) for x, y in enumerate ( reversed ( chars ) ) ) check = 11 - ( val % 11 ) if check == 10 : check = "X" elif check == 11 : check = "0" else : # ISBN-13 val = sum ( ( x % 2 * 2 + 1 ) * int ( y ) for x, y in enumerate ( chars ) ) check = 10 - ( val % 10 ) if check == 10 : check = "0" if ( str ( check ) == last ) : print u " ISBN" else : print u " ISBN" else : print u " ISBN"
# -*- coding: utf-8 -*- # file: isbn_check.py import re import sys # ISBN-10 ISBN-13 regex = re . compile ( "^(?:ISBN(?:-1[03])?:? )?(?=[-0-9 ]{17}$|[-0-9X ]{13}$|[0-9X]{10}$)(?:97[89][- ]?)?[0-9]{1,5}[- ]?(?:[0-9]+[- ]?){2}[0-9X]$" ) subject = sys . argv [ 1 ] if regex. search ( subject ) : # , ISBN cbuf = re . sub ( "[^0-9X]" , "" , subject ) # chars = list ( ) # for item in cbuf [ : ] : chars. append ( item ) # chars last last = chars. pop ( ) if len ( chars ) == 9 : # ISBN-10 val = sum ( ( x + 2 ) * int ( y ) for x, y in enumerate ( reversed ( chars ) ) ) check = 11 - ( val % 11 ) if check == 10 : check = "X" elif check == 11 : check = "0" else : # ISBN-13 val = sum ( ( x % 2 * 2 + 1 ) * int ( y ) for x, y in enumerate ( chars ) ) check = 10 - ( val % 10 ) if check == 10 : check = "0" if ( str ( check ) == last ) : print u " ISBN" else : print u " ISBN" else : print u " ISBN"
# -*- coding: utf-8 -*- # file: isbn_check.py import re import sys # ISBN-10 ISBN-13 regex = re . compile ( "^(?:ISBN(?:-1[03])?:? )?(?=[-0-9 ]{17}$|[-0-9X ]{13}$|[0-9X]{10}$)(?:97[89][- ]?)?[0-9]{1,5}[- ]?(?:[0-9]+[- ]?){2}[0-9X]$" ) subject = sys . argv [ 1 ] if regex. search ( subject ) : # , ISBN cbuf = re . sub ( "[^0-9X]" , "" , subject ) # chars = list ( ) # for item in cbuf [ : ] : chars. append ( item ) # chars last last = chars. pop ( ) if len ( chars ) == 9 : # ISBN-10 val = sum ( ( x + 2 ) * int ( y ) for x, y in enumerate ( reversed ( chars ) ) ) check = 11 - ( val % 11 ) if check == 10 : check = "X" elif check == 11 : check = "0" else : # ISBN-13 val = sum ( ( x % 2 * 2 + 1 ) * int ( y ) for x, y in enumerate ( chars ) ) check = 10 - ( val % 10 ) if check == 10 : check = "0" if ( str ( check ) == last ) : print u " ISBN" else : print u " ISBN" else : print u " ISBN"
# -*- coding: utf-8 -*- # file: isbn_check.py import re import sys # ISBN-10 ISBN-13 regex = re . compile ( "^(?:ISBN(?:-1[03])?:? )?(?=[-0-9 ]{17}$|[-0-9X ]{13}$|[0-9X]{10}$)(?:97[89][- ]?)?[0-9]{1,5}[- ]?(?:[0-9]+[- ]?){2}[0-9X]$" ) subject = sys . argv [ 1 ] if regex. search ( subject ) : # , ISBN cbuf = re . sub ( "[^0-9X]" , "" , subject ) # chars = list ( ) # for item in cbuf [ : ] : chars. append ( item ) # chars last last = chars. pop ( ) if len ( chars ) == 9 : # ISBN-10 val = sum ( ( x + 2 ) * int ( y ) for x, y in enumerate ( reversed ( chars ) ) ) check = 11 - ( val % 11 ) if check == 10 : check = "X" elif check == 11 : check = "0" else : # ISBN-13 val = sum ( ( x % 2 * 2 + 1 ) * int ( y ) for x, y in enumerate ( chars ) ) check = 10 - ( val % 10 ) if check == 10 : check = "0" if ( str ( check ) == last ) : print u " ISBN" else : print u " ISBN" else : print u " ISBN"
# -*- coding: utf-8 -*- # file: isbn_check.py import re import sys # ISBN-10 ISBN-13 regex = re . compile ( "^(?:ISBN(?:-1[03])?:? )?(?=[-0-9 ]{17}$|[-0-9X ]{13}$|[0-9X]{10}$)(?:97[89][- ]?)?[0-9]{1,5}[- ]?(?:[0-9]+[- ]?){2}[0-9X]$" ) subject = sys . argv [ 1 ] if regex. search ( subject ) : # , ISBN cbuf = re . sub ( "[^0-9X]" , "" , subject ) # chars = list ( ) # for item in cbuf [ : ] : chars. append ( item ) # chars last last = chars. pop ( ) if len ( chars ) == 9 : # ISBN-10 val = sum ( ( x + 2 ) * int ( y ) for x, y in enumerate ( reversed ( chars ) ) ) check = 11 - ( val % 11 ) if check == 10 : check = "X" elif check == 11 : check = "0" else : # ISBN-13 val = sum ( ( x % 2 * 2 + 1 ) * int ( y ) for x, y in enumerate ( chars ) ) check = 10 - ( val % 10 ) if check == 10 : check = "0" if ( str ( check ) == last ) : print u " ISBN" else : print u " ISBN" else : print u " ISBN"
# -*- coding: utf-8 -*- # file: isbn_check.py import re import sys # ISBN-10 ISBN-13 regex = re . compile ( "^(?:ISBN(?:-1[03])?:? )?(?=[-0-9 ]{17}$|[-0-9X ]{13}$|[0-9X]{10}$)(?:97[89][- ]?)?[0-9]{1,5}[- ]?(?:[0-9]+[- ]?){2}[0-9X]$" ) subject = sys . argv [ 1 ] if regex. search ( subject ) : # , ISBN cbuf = re . sub ( "[^0-9X]" , "" , subject ) # chars = list ( ) # for item in cbuf [ : ] : chars. append ( item ) # chars last last = chars. pop ( ) if len ( chars ) == 9 : # ISBN-10 val = sum ( ( x + 2 ) * int ( y ) for x, y in enumerate ( reversed ( chars ) ) ) check = 11 - ( val % 11 ) if check == 10 : check = "X" elif check == 11 : check = "0" else : # ISBN-13 val = sum ( ( x % 2 * 2 + 1 ) * int ( y ) for x, y in enumerate ( chars ) ) check = 10 - ( val % 10 ) if check == 10 : check = "0" if ( str ( check ) == last ) : print u " ISBN" else : print u " ISBN" else : print u " ISBN"
# -*- coding: utf-8 -*- # file: isbn_check.py import re import sys # ISBN-10 ISBN-13 regex = re . compile ( "^(?:ISBN(?:-1[03])?:? )?(?=[-0-9 ]{17}$|[-0-9X ]{13}$|[0-9X]{10}$)(?:97[89][- ]?)?[0-9]{1,5}[- ]?(?:[0-9]+[- ]?){2}[0-9X]$" ) subject = sys . argv [ 1 ] if regex. search ( subject ) : # , ISBN cbuf = re . sub ( "[^0-9X]" , "" , subject ) # chars = list ( ) # for item in cbuf [ : ] : chars. append ( item ) # chars last last = chars. pop ( ) if len ( chars ) == 9 : # ISBN-10 val = sum ( ( x + 2 ) * int ( y ) for x, y in enumerate ( reversed ( chars ) ) ) check = 11 - ( val % 11 ) if check == 10 : check = "X" elif check == 11 : check = "0" else : # ISBN-13 val = sum ( ( x % 2 * 2 + 1 ) * int ( y ) for x, y in enumerate ( chars ) ) check = 10 - ( val % 10 ) if check == 10 : check = "0" if ( str ( check ) == last ) : print u " ISBN" else : print u " ISBN" else : print u " ISBN"
# -*- coding: utf-8 -*- # file: isbn_check.py import re import sys # ISBN-10 ISBN-13 regex = re . compile ( "^(?:ISBN(?:-1[03])?:? )?(?=[-0-9 ]{17}$|[-0-9X ]{13}$|[0-9X]{10}$)(?:97[89][- ]?)?[0-9]{1,5}[- ]?(?:[0-9]+[- ]?){2}[0-9X]$" ) subject = sys . argv [ 1 ] if regex. search ( subject ) : # , ISBN cbuf = re . sub ( "[^0-9X]" , "" , subject ) # chars = list ( ) # for item in cbuf [ : ] : chars. append ( item ) # chars last last = chars. pop ( ) if len ( chars ) == 9 : # ISBN-10 val = sum ( ( x + 2 ) * int ( y ) for x, y in enumerate ( reversed ( chars ) ) ) check = 11 - ( val % 11 ) if check == 10 : check = "X" elif check == 11 : check = "0" else : # ISBN-13 val = sum ( ( x % 2 * 2 + 1 ) * int ( y ) for x, y in enumerate ( chars ) ) check = 10 - ( val % 10 ) if check == 10 : check = "0" if ( str ( check ) == last ) : print u " ISBN" else : print u " ISBN" else : print u " ISBN"
# -*- coding: utf-8 -*- # file: isbn_check.py import re import sys # ISBN-10 ISBN-13 regex = re . compile ( "^(?:ISBN(?:-1[03])?:? )?(?=[-0-9 ]{17}$|[-0-9X ]{13}$|[0-9X]{10}$)(?:97[89][- ]?)?[0-9]{1,5}[- ]?(?:[0-9]+[- ]?){2}[0-9X]$" ) subject = sys . argv [ 1 ] if regex. search ( subject ) : # , ISBN cbuf = re . sub ( "[^0-9X]" , "" , subject ) # chars = list ( ) # for item in cbuf [ : ] : chars. append ( item ) # chars last last = chars. pop ( ) if len ( chars ) == 9 : # ISBN-10 val = sum ( ( x + 2 ) * int ( y ) for x, y in enumerate ( reversed ( chars ) ) ) check = 11 - ( val % 11 ) if check == 10 : check = "X" elif check == 11 : check = "0" else : # ISBN-13 val = sum ( ( x % 2 * 2 + 1 ) * int ( y ) for x, y in enumerate ( chars ) ) check = 10 - ( val % 10 ) if check == 10 : check = "0" if ( str ( check ) == last ) : print u " ISBN" else : print u " ISBN" else : print u " ISBN"
# -*- coding: utf-8 -*- # file: isbn_check.py import re import sys # ISBN-10 ISBN-13 regex = re . compile ( "^(?:ISBN(?:-1[03])?:? )?(?=[-0-9 ]{17}$|[-0-9X ]{13}$|[0-9X]{10}$)(?:97[89][- ]?)?[0-9]{1,5}[- ]?(?:[0-9]+[- ]?){2}[0-9X]$" ) subject = sys . argv [ 1 ] if regex. search ( subject ) : # , ISBN cbuf = re . sub ( "[^0-9X]" , "" , subject ) # chars = list ( ) # for item in cbuf [ : ] : chars. append ( item ) # chars last last = chars. pop ( ) if len ( chars ) == 9 : # ISBN-10 val = sum ( ( x + 2 ) * int ( y ) for x, y in enumerate ( reversed ( chars ) ) ) check = 11 - ( val % 11 ) if check == 10 : check = "X" elif check == 11 : check = "0" else : # ISBN-13 val = sum ( ( x % 2 * 2 + 1 ) * int ( y ) for x, y in enumerate ( chars ) ) check = 10 - ( val % 10 ) if check == 10 : check = "0" if ( str ( check ) == last ) : print u " ISBN" else : print u " ISBN" else : print u " ISBN"
# -*- coding: utf-8 -*- # file: isbn_check.py import re import sys # ISBN-10 ISBN-13 regex = re . compile ( "^(?:ISBN(?:-1[03])?:? )?(?=[-0-9 ]{17}$|[-0-9X ]{13}$|[0-9X]{10}$)(?:97[89][- ]?)?[0-9]{1,5}[- ]?(?:[0-9]+[- ]?){2}[0-9X]$" ) subject = sys . argv [ 1 ] if regex. search ( subject ) : # , ISBN cbuf = re . sub ( "[^0-9X]" , "" , subject ) # chars = list ( ) # for item in cbuf [ : ] : chars. append ( item ) # chars last last = chars. pop ( ) if len ( chars ) == 9 : # ISBN-10 val = sum ( ( x + 2 ) * int ( y ) for x, y in enumerate ( reversed ( chars ) ) ) check = 11 - ( val % 11 ) if check == 10 : check = "X" elif check == 11 : check = "0" else : # ISBN-13 val = sum ( ( x % 2 * 2 + 1 ) * int ( y ) for x, y in enumerate ( chars ) ) check = 10 - ( val % 10 ) if check == 10 : check = "0" if ( str ( check ) == last ) : print u " ISBN" else : print u " ISBN" else : print u " ISBN"
# -*- coding: utf-8 -*- # file: isbn_check.py import re import sys # ISBN-10 ISBN-13 regex = re . compile ( "^(?:ISBN(?:-1[03])?:? )?(?=[-0-9 ]{17}$|[-0-9X ]{13}$|[0-9X]{10}$)(?:97[89][- ]?)?[0-9]{1,5}[- ]?(?:[0-9]+[- ]?){2}[0-9X]$" ) subject = sys . argv [ 1 ] if regex. search ( subject ) : # , ISBN cbuf = re . sub ( "[^0-9X]" , "" , subject ) # chars = list ( ) # for item in cbuf [ : ] : chars. append ( item ) # chars last last = chars. pop ( ) if len ( chars ) == 9 : # ISBN-10 val = sum ( ( x + 2 ) * int ( y ) for x, y in enumerate ( reversed ( chars ) ) ) check = 11 - ( val % 11 ) if check == 10 : check = "X" elif check == 11 : check = "0" else : # ISBN-13 val = sum ( ( x % 2 * 2 + 1 ) * int ( y ) for x, y in enumerate ( chars ) ) check = 10 - ( val % 10 ) if check == 10 : check = "0" if ( str ( check ) == last ) : print u " ISBN" else : print u " ISBN" else : print u " ISBN"
# -*- coding: utf-8 -*- # file: isbn_check.py import re import sys # ISBN-10 ISBN-13 regex = re . compile ( "^(?:ISBN(?:-1[03])?:? )?(?=[-0-9 ]{17}$|[-0-9X ]{13}$|[0-9X]{10}$)(?:97[89][- ]?)?[0-9]{1,5}[- ]?(?:[0-9]+[- ]?){2}[0-9X]$" ) subject = sys . argv [ 1 ] if regex. search ( subject ) : # , ISBN cbuf = re . sub ( "[^0-9X]" , "" , subject ) # chars = list ( ) # for item in cbuf [ : ] : chars. append ( item ) # chars last last = chars. pop ( ) if len ( chars ) == 9 : # ISBN-10 val = sum ( ( x + 2 ) * int ( y ) for x, y in enumerate ( reversed ( chars ) ) ) check = 11 - ( val % 11 ) if check == 10 : check = "X" elif check == 11 : check = "0" else : # ISBN-13 val = sum ( ( x % 2 * 2 + 1 ) * int ( y ) for x, y in enumerate ( chars ) ) check = 10 - ( val % 10 ) if check == 10 : check = "0" if ( str ( check ) == last ) : print u " ISBN" else : print u " ISBN" else : print u " ISBN"
# -*- coding: utf-8 -*- # file: isbn_check.py import re import sys # ISBN-10 ISBN-13 regex = re . compile ( "^(?:ISBN(?:-1[03])?:? )?(?=[-0-9 ]{17}$|[-0-9X ]{13}$|[0-9X]{10}$)(?:97[89][- ]?)?[0-9]{1,5}[- ]?(?:[0-9]+[- ]?){2}[0-9X]$" ) subject = sys . argv [ 1 ] if regex. search ( subject ) : # , ISBN cbuf = re . sub ( "[^0-9X]" , "" , subject ) # chars = list ( ) # for item in cbuf [ : ] : chars. append ( item ) # chars last last = chars. pop ( ) if len ( chars ) == 9 : # ISBN-10 val = sum ( ( x + 2 ) * int ( y ) for x, y in enumerate ( reversed ( chars ) ) ) check = 11 - ( val % 11 ) if check == 10 : check = "X" elif check == 11 : check = "0" else : # ISBN-13 val = sum ( ( x % 2 * 2 + 1 ) * int ( y ) for x, y in enumerate ( chars ) ) check = 10 - ( val % 10 ) if check == 10 : check = "0" if ( str ( check ) == last ) : print u " ISBN" else : print u " ISBN" else : print u " ISBN"
# -*- coding: utf-8 -*- # file: isbn_check.py import re import sys # ISBN-10 ISBN-13 regex = re . compile ( "^(?:ISBN(?:-1[03])?:? )?(?=[-0-9 ]{17}$|[-0-9X ]{13}$|[0-9X]{10}$)(?:97[89][- ]?)?[0-9]{1,5}[- ]?(?:[0-9]+[- ]?){2}[0-9X]$" ) subject = sys . argv [ 1 ] if regex. search ( subject ) : # , ISBN cbuf = re . sub ( "[^0-9X]" , "" , subject ) # chars = list ( ) # for item in cbuf [ : ] : chars. append ( item ) # chars last last = chars. pop ( ) if len ( chars ) == 9 : # ISBN-10 val = sum ( ( x + 2 ) * int ( y ) for x, y in enumerate ( reversed ( chars ) ) ) check = 11 - ( val % 11 ) if check == 10 : check = "X" elif check == 11 : check = "0" else : # ISBN-13 val = sum ( ( x % 2 * 2 + 1 ) * int ( y ) for x, y in enumerate ( chars ) ) check = 10 - ( val % 10 ) if check == 10 : check = "0" if ( str ( check ) == last ) : print u " ISBN" else : print u " ISBN" else : print u " ISBN"
# -*- coding: utf-8 -*- # file: isbn_check.py import re import sys # ISBN-10 ISBN-13 regex = re . compile ( "^(?:ISBN(?:-1[03])?:? )?(?=[-0-9 ]{17}$|[-0-9X ]{13}$|[0-9X]{10}$)(?:97[89][- ]?)?[0-9]{1,5}[- ]?(?:[0-9]+[- ]?){2}[0-9X]$" ) subject = sys . argv [ 1 ] if regex. search ( subject ) : # , ISBN cbuf = re . sub ( "[^0-9X]" , "" , subject ) # chars = list ( ) # for item in cbuf [ : ] : chars. append ( item ) # chars last last = chars. pop ( ) if len ( chars ) == 9 : # ISBN-10 val = sum ( ( x + 2 ) * int ( y ) for x, y in enumerate ( reversed ( chars ) ) ) check = 11 - ( val % 11 ) if check == 10 : check = "X" elif check == 11 : check = "0" else : # ISBN-13 val = sum ( ( x % 2 * 2 + 1 ) * int ( y ) for x, y in enumerate ( chars ) ) check = 10 - ( val % 10 ) if check == 10 : check = "0" if ( str ( check ) == last ) : print u " ISBN" else : print u " ISBN" else : print u " ISBN"
# -*- coding: utf-8 -*- # file: isbn_check.py import re import sys # ISBN-10 ISBN-13 regex = re . compile ( "^(?:ISBN(?:-1[03])?:? )?(?=[-0-9 ]{17}$|[-0-9X ]{13}$|[0-9X]{10}$)(?:97[89][- ]?)?[0-9]{1,5}[- ]?(?:[0-9]+[- ]?){2}[0-9X]$" ) subject = sys . argv [ 1 ] if regex. search ( subject ) : # , ISBN cbuf = re . sub ( "[^0-9X]" , "" , subject ) # chars = list ( ) # for item in cbuf [ : ] : chars. append ( item ) # chars last last = chars. pop ( ) if len ( chars ) == 9 : # ISBN-10 val = sum ( ( x + 2 ) * int ( y ) for x, y in enumerate ( reversed ( chars ) ) ) check = 11 - ( val % 11 ) if check == 10 : check = "X" elif check == 11 : check = "0" else : # ISBN-13 val = sum ( ( x % 2 * 2 + 1 ) * int ( y ) for x, y in enumerate ( chars ) ) check = 10 - ( val % 10 ) if check == 10 : check = "0" if ( str ( check ) == last ) : print u " ISBN" else : print u " ISBN" else : print u " ISBN"
# -*- coding: utf-8 -*- # file: isbn_check.py import re import sys # ISBN-10 ISBN-13 regex = re . compile ( "^(?:ISBN(?:-1[03])?:? )?(?=[-0-9 ]{17}$|[-0-9X ]{13}$|[0-9X]{10}$)(?:97[89][- ]?)?[0-9]{1,5}[- ]?(?:[0-9]+[- ]?){2}[0-9X]$" ) subject = sys . argv [ 1 ] if regex. search ( subject ) : # , ISBN cbuf = re . sub ( "[^0-9X]" , "" , subject ) # chars = list ( ) # for item in cbuf [ : ] : chars. append ( item ) # chars last last = chars. pop ( ) if len ( chars ) == 9 : # ISBN-10 val = sum ( ( x + 2 ) * int ( y ) for x, y in enumerate ( reversed ( chars ) ) ) check = 11 - ( val % 11 ) if check == 10 : check = "X" elif check == 11 : check = "0" else : # ISBN-13 val = sum ( ( x % 2 * 2 + 1 ) * int ( y ) for x, y in enumerate ( chars ) ) check = 10 - ( val % 10 ) if check == 10 : check = "0" if ( str ( check ) == last ) : print u " ISBN" else : print u " ISBN" else : print u " ISBN"
# -*- coding: utf-8 -*- # file: isbn_check.py import re import sys # ISBN-10 ISBN-13 regex = re . compile ( "^(?:ISBN(?:-1[03])?:? )?(?=[-0-9 ]{17}$|[-0-9X ]{13}$|[0-9X]{10}$)(?:97[89][- ]?)?[0-9]{1,5}[- ]?(?:[0-9]+[- ]?){2}[0-9X]$" ) subject = sys . argv [ 1 ] if regex. search ( subject ) : # , ISBN cbuf = re . sub ( "[^0-9X]" , "" , subject ) # chars = list ( ) # for item in cbuf [ : ] : chars. append ( item ) # chars last last = chars. pop ( ) if len ( chars ) == 9 : # ISBN-10 val = sum ( ( x + 2 ) * int ( y ) for x, y in enumerate ( reversed ( chars ) ) ) check = 11 - ( val % 11 ) if check == 10 : check = "X" elif check == 11 : check = "0" else : # ISBN-13 val = sum ( ( x % 2 * 2 + 1 ) * int ( y ) for x, y in enumerate ( chars ) ) check = 10 - ( val % 10 ) if check == 10 : check = "0" if ( str ( check ) == last ) : print u " ISBN" else : print u " ISBN" else : print u " ISBN"
# -*- coding: utf-8 -*- # file: isbn_check.py import re import sys # ISBN-10 ISBN-13 regex = re . compile ( "^(?:ISBN(?:-1[03])?:? )?(?=[-0-9 ]{17}$|[-0-9X ]{13}$|[0-9X]{10}$)(?:97[89][- ]?)?[0-9]{1,5}[- ]?(?:[0-9]+[- ]?){2}[0-9X]$" ) subject = sys . argv [ 1 ] if regex. search ( subject ) : # , ISBN cbuf = re . sub ( "[^0-9X]" , "" , subject ) # chars = list ( ) # for item in cbuf [ : ] : chars. append ( item ) # chars last last = chars. pop ( ) if len ( chars ) == 9 : # ISBN-10 val = sum ( ( x + 2 ) * int ( y ) for x, y in enumerate ( reversed ( chars ) ) ) check = 11 - ( val % 11 ) if check == 10 : check = "X" elif check == 11 : check = "0" else : # ISBN-13 val = sum ( ( x % 2 * 2 + 1 ) * int ( y ) for x, y in enumerate ( chars ) ) check = 10 - ( val % 10 ) if check == 10 : check = "0" if ( str ( check ) == last ) : print u " ISBN" else : print u " ISBN" else : print u " ISBN"
# -*- coding: utf-8 -*- # file: isbn_check.py import re import sys # ISBN-10 ISBN-13 regex = re . compile ( "^(?:ISBN(?:-1[03])?:? )?(?=[-0-9 ]{17}$|[-0-9X ]{13}$|[0-9X]{10}$)(?:97[89][- ]?)?[0-9]{1,5}[- ]?(?:[0-9]+[- ]?){2}[0-9X]$" ) subject = sys . argv [ 1 ] if regex. search ( subject ) : # , ISBN cbuf = re . sub ( "[^0-9X]" , "" , subject ) # chars = list ( ) # for item in cbuf [ : ] : chars. append ( item ) # chars last last = chars. pop ( ) if len ( chars ) == 9 : # ISBN-10 val = sum ( ( x + 2 ) * int ( y ) for x, y in enumerate ( reversed ( chars ) ) ) check = 11 - ( val % 11 ) if check == 10 : check = "X" elif check == 11 : check = "0" else : # ISBN-13 val = sum ( ( x % 2 * 2 + 1 ) * int ( y ) for x, y in enumerate ( chars ) ) check = 10 - ( val % 10 ) if check == 10 : check = "0" if ( str ( check ) == last ) : print u " ISBN" else : print u " ISBN" else : print u " ISBN"
# -*- coding: utf-8 -*- # file: isbn_check.py import re import sys # ISBN-10 ISBN-13 regex = re . compile ( "^(?:ISBN(?:-1[03])?:? )?(?=[-0-9 ]{17}$|[-0-9X ]{13}$|[0-9X]{10}$)(?:97[89][- ]?)?[0-9]{1,5}[- ]?(?:[0-9]+[- ]?){2}[0-9X]$" ) subject = sys . argv [ 1 ] if regex. search ( subject ) : # , ISBN cbuf = re . sub ( "[^0-9X]" , "" , subject ) # chars = list ( ) # for item in cbuf [ : ] : chars. append ( item ) # chars last last = chars. pop ( ) if len ( chars ) == 9 : # ISBN-10 val = sum ( ( x + 2 ) * int ( y ) for x, y in enumerate ( reversed ( chars ) ) ) check = 11 - ( val % 11 ) if check == 10 : check = "X" elif check == 11 : check = "0" else : # ISBN-13 val = sum ( ( x % 2 * 2 + 1 ) * int ( y ) for x, y in enumerate ( chars ) ) check = 10 - ( val % 10 ) if check == 10 : check = "0" if ( str ( check ) == last ) : print u " ISBN" else : print u " ISBN" else : print u " ISBN"
# -*- coding: utf-8 -*- # file: isbn_check.py import re import sys # ISBN-10 ISBN-13 regex = re . compile ( "^(?:ISBN(?:-1[03])?:? )?(?=[-0-9 ]{17}$|[-0-9X ]{13}$|[0-9X]{10}$)(?:97[89][- ]?)?[0-9]{1,5}[- ]?(?:[0-9]+[- ]?){2}[0-9X]$" ) subject = sys . argv [ 1 ] if regex. search ( subject ) : # , ISBN cbuf = re . sub ( "[^0-9X]" , "" , subject ) # chars = list ( ) # for item in cbuf [ : ] : chars. append ( item ) # chars last last = chars. pop ( ) if len ( chars ) == 9 : # ISBN-10 val = sum ( ( x + 2 ) * int ( y ) for x, y in enumerate ( reversed ( chars ) ) ) check = 11 - ( val % 11 ) if check == 10 : check = "X" elif check == 11 : check = "0" else : # ISBN-13 val = sum ( ( x % 2 * 2 + 1 ) * int ( y ) for x, y in enumerate ( chars ) ) check = 10 - ( val % 10 ) if check == 10 : check = "0" if ( str ( check ) == last ) : print u " ISBN" else : print u " ISBN" else : print u " ISBN"
# -*- coding: utf-8 -*- # file: isbn_check.py import re import sys # ISBN-10 ISBN-13 regex = re . compile ( "^(?:ISBN(?:-1[03])?:? )?(?=[-0-9 ]{17}$|[-0-9X ]{13}$|[0-9X]{10}$)(?:97[89][- ]?)?[0-9]{1,5}[- ]?(?:[0-9]+[- ]?){2}[0-9X]$" ) subject = sys . argv [ 1 ] if regex. search ( subject ) : # , ISBN cbuf = re . sub ( "[^0-9X]" , "" , subject ) # chars = list ( ) # for item in cbuf [ : ] : chars. append ( item ) # chars last last = chars. pop ( ) if len ( chars ) == 9 : # ISBN-10 val = sum ( ( x + 2 ) * int ( y ) for x, y in enumerate ( reversed ( chars ) ) ) check = 11 - ( val % 11 ) if check == 10 : check = "X" elif check == 11 : check = "0" else : # ISBN-13 val = sum ( ( x % 2 * 2 + 1 ) * int ( y ) for x, y in enumerate ( chars ) ) check = 10 - ( val % 10 ) if check == 10 : check = "0" if ( str ( check ) == last ) : print u " ISBN" else : print u " ISBN" else : print u " ISBN"
# -*- coding: utf-8 -*- # file: isbn_check.py import re import sys # ISBN-10 ISBN-13 regex = re . compile ( "^(?:ISBN(?:-1[03])?:? )?(?=[-0-9 ]{17}$|[-0-9X ]{13}$|[0-9X]{10}$)(?:97[89][- ]?)?[0-9]{1,5}[- ]?(?:[0-9]+[- ]?){2}[0-9X]$" ) subject = sys . argv [ 1 ] if regex. search ( subject ) : # , ISBN cbuf = re . sub ( "[^0-9X]" , "" , subject ) # chars = list ( ) # for item in cbuf [ : ] : chars. append ( item ) # chars last last = chars. pop ( ) if len ( chars ) == 9 : # ISBN-10 val = sum ( ( x + 2 ) * int ( y ) for x, y in enumerate ( reversed ( chars ) ) ) check = 11 - ( val % 11 ) if check == 10 : check = "X" elif check == 11 : check = "0" else : # ISBN-13 val = sum ( ( x % 2 * 2 + 1 ) * int ( y ) for x, y in enumerate ( chars ) ) check = 10 - ( val % 10 ) if check == 10 : check = "0" if ( str ( check ) == last ) : print u " ISBN" else : print u " ISBN" else : print u " ISBN"
# -*- coding: utf-8 -*- # file: isbn_check.py import re import sys # ISBN-10 ISBN-13 regex = re . compile ( "^(?:ISBN(?:-1[03])?:? )?(?=[-0-9 ]{17}$|[-0-9X ]{13}$|[0-9X]{10}$)(?:97[89][- ]?)?[0-9]{1,5}[- ]?(?:[0-9]+[- ]?){2}[0-9X]$" ) subject = sys . argv [ 1 ] if regex. search ( subject ) : # , ISBN cbuf = re . sub ( "[^0-9X]" , "" , subject ) # chars = list ( ) # for item in cbuf [ : ] : chars. append ( item ) # chars last last = chars. pop ( ) if len ( chars ) == 9 : # ISBN-10 val = sum ( ( x + 2 ) * int ( y ) for x, y in enumerate ( reversed ( chars ) ) ) check = 11 - ( val % 11 ) if check == 10 : check = "X" elif check == 11 : check = "0" else : # ISBN-13 val = sum ( ( x % 2 * 2 + 1 ) * int ( y ) for x, y in enumerate ( chars ) ) check = 10 - ( val % 10 ) if check == 10 : check = "0" if ( str ( check ) == last ) : print u " ISBN" else : print u " ISBN" else : print u " ISBN"
# -*- coding: utf-8 -*- # file: isbn_check.py import re import sys # ISBN-10 ISBN-13 regex = re . compile ( "^(?:ISBN(?:-1[03])?:? )?(?=[-0-9 ]{17}$|[-0-9X ]{13}$|[0-9X]{10}$)(?:97[89][- ]?)?[0-9]{1,5}[- ]?(?:[0-9]+[- ]?){2}[0-9X]$" ) subject = sys . argv [ 1 ] if regex. search ( subject ) : # , ISBN cbuf = re . sub ( "[^0-9X]" , "" , subject ) # chars = list ( ) # for item in cbuf [ : ] : chars. append ( item ) # chars last last = chars. pop ( ) if len ( chars ) == 9 : # ISBN-10 val = sum ( ( x + 2 ) * int ( y ) for x, y in enumerate ( reversed ( chars ) ) ) check = 11 - ( val % 11 ) if check == 10 : check = "X" elif check == 11 : check = "0" else : # ISBN-13 val = sum ( ( x % 2 * 2 + 1 ) * int ( y ) for x, y in enumerate ( chars ) ) check = 10 - ( val % 10 ) if check == 10 : check = "0" if ( str ( check ) == last ) : print u " ISBN" else : print u " ISBN" else : print u " ISBN"
# -*- coding: utf-8 -*- # file: isbn_check.py import re import sys # ISBN-10 ISBN-13 regex = re . compile ( "^(?:ISBN(?:-1[03])?:? )?(?=[-0-9 ]{17}$|[-0-9X ]{13}$|[0-9X]{10}$)(?:97[89][- ]?)?[0-9]{1,5}[- ]?(?:[0-9]+[- ]?){2}[0-9X]$" ) subject = sys . argv [ 1 ] if regex. search ( subject ) : # , ISBN cbuf = re . sub ( "[^0-9X]" , "" , subject ) # chars = list ( ) # for item in cbuf [ : ] : chars. append ( item ) # chars last last = chars. pop ( ) if len ( chars ) == 9 : # ISBN-10 val = sum ( ( x + 2 ) * int ( y ) for x, y in enumerate ( reversed ( chars ) ) ) check = 11 - ( val % 11 ) if check == 10 : check = "X" elif check == 11 : check = "0" else : # ISBN-13 val = sum ( ( x % 2 * 2 + 1 ) * int ( y ) for x, y in enumerate ( chars ) ) check = 10 - ( val % 10 ) if check == 10 : check = "0" if ( str ( check ) == last ) : print u " ISBN" else : print u " ISBN" else : print u " ISBN"
# -*- coding: utf-8 -*- # file: isbn_check.py import re import sys # ISBN-10 ISBN-13 regex = re . compile ( "^(?:ISBN(?:-1[03])?:? )?(?=[-0-9 ]{17}$|[-0-9X ]{13}$|[0-9X]{10}$)(?:97[89][- ]?)?[0-9]{1,5}[- ]?(?:[0-9]+[- ]?){2}[0-9X]$" ) subject = sys . argv [ 1 ] if regex. search ( subject ) : # , ISBN cbuf = re . sub ( "[^0-9X]" , "" , subject ) # chars = list ( ) # for item in cbuf [ : ] : chars. append ( item ) # chars last last = chars. pop ( ) if len ( chars ) == 9 : # ISBN-10 val = sum ( ( x + 2 ) * int ( y ) for x, y in enumerate ( reversed ( chars ) ) ) check = 11 - ( val % 11 ) if check == 10 : check = "X" elif check == 11 : check = "0" else : # ISBN-13 val = sum ( ( x % 2 * 2 + 1 ) * int ( y ) for x, y in enumerate ( chars ) ) check = 10 - ( val % 10 ) if check == 10 : check = "0" if ( str ( check ) == last ) : print u " ISBN" else : print u " ISBN" else : print u " ISBN"
^ #
(?: # ,
ISBN # ISBN
(?:-1[03])? # "-10" "-13"
:? # ":"
\ # ()
)? #
(?= #
[-0-9 ]{17}$ # 17 ,
| # .
[-0-9X ]{13}$ # 13 , , "X"
| # .
[0-9X]{10}$ # 10 "X",
) #
(?: # ,
97[89] # "978" "979"
[-\ ]? # "-" ()
)? #
[0-9]{1,5} # 1 5
[-\ ]? # "-" ()
(?: # ,
[0-9]+ # , 1
[-\ ]? # "-" ()
){2} # 2
[0-9X] # "X"
$ #
Source: https://habr.com/ru/post/80430/
All Articles