Regular expression for ISBN 13

Hi everyone, I keep trying to make a regular expression for XML in my .xsd.

This expression should check ISBN-13, but I could not get further than this:

ISBN (978|979)[ |-][0-9]{1,5}[ |-][0-9]{1,7}[ |-][0-9]{1,7}[0-9]{1} 

This is normal if someone fills in the correct ISBN13, but it is also possible to make ISBNs that are much longer (for example, you can still make the first block of numbers 5 long, and the second block 7 digits and the third also 7 digits).

I am very new to this thread and I cannot solve this problem, so I hope someone can help me or solve my problem.

I know what ISBN 13 consists of, I checked Wikipedia and other websites, but my actual problem is the regular expression it self.

I hope they didn’t ask about this before, so I’m sorry if someone asked this question before. jajay07

+4
source share
3 answers

According to http://regexlib.com/REDetails.aspx?regexp_id=1747 regex

 ISBN(-1(?:(0)|3))?:?\x20+(?(1)(?(2)(?:(?=.{13}$)\d{1,5}([ -])\d{1,7}\3\d{1,6}\3(?:\d|x)$)|(?:(?=.{17}$)97(?:8|9)([ -])\d{1,5}\4\d{1,7}\4\d{1,6}\4\d$))|(?(.{13}$)(?:\d{1,5}([ -])\d{1,7}\5\d{1,6}\5(?:\d|x)$)|(?:(?=.{17}$)97(?:8|9)([ -])\d{1,5}\6\d{1,7}\6\d{1,6}\6\d$))) 

matches both the old 10-digit ISBN and the new 13-digit ISBN.

You can easily (perhaps not very easy) use the part of this regular expression that you need.

+6
source
 ISBN(?:-13)?:?\x20*(?=.{17}$)97(?:8|9)([ -])\d{1,5}\1\d{1,7}\1\d{1,6}\1\d$ 

Should match:
ISBN-13: 978-1-4028-9462-6
ISBN: 978-1-4028-9462-6
ISBN-13 978-1-4028-9462-6
ISBN 978-1-4028-9462-6

+3
source

See also ISBN on xFront:

We have created a simpleType XML Schema for ISBN. This ISBN Definition covers all legal ISBN formats worldwide.

+2
source

All Articles