ISBN 13 的正则表达式 [英] Regular expression for an ISBN 13

查看:65
本文介绍了ISBN 13 的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我一直在尝试在我的 .xsd 中为 XML 创建正则表达式.

Hi all I'm trying all the time to make a regular expression for XML in my .xsd.

这个表达式应该验证一个 ISBN-13 编号,但我无法得到更多:

This expression should verify an ISBN-13 number but I couldn't get further than this:

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

如果有人填写正确的 ISBN13,这是可以的,但也可以制作更长的 ISBN(例如,仍然可以制作第一个数字 5 长和第二个 7 位数字和第三个也是 7 位数字).

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

我对这个话题很陌生,我无法解决这个问题,因此我希望有人能帮助我或解决我的问题.

I am very new to this topic and I cannot solve this problem, therefore I hope somebody could help me or solve my problem.

我知道 ISBN 13 由什么组成,我查看了维基百科和其他网站,但我的实际问题是它本身的正则表达式.

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

我希望这不是早点问的,所以如果有人早点问这个问题,我很抱歉.jajay07

I hope that this wasnt asked earlier, so I am sorry if somebody asked this question earlier. jajay07

推荐答案

根据 http://regexlib.com/REDetails.aspx?regexp_id=1747 正则表达式

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$)))

匹配旧的 10 位 ISBN 和新的 13 位 ISBN.

matches both the old 10 digit ISBNs and the new 13 digit ISBNs.

您可以轻松(可能不太容易)使用此正则表达式中您需要的部分.

You can easily (maybe not very easily) use the part of this regexp that you need.

这篇关于ISBN 13 的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆