logicslab
asked on
Regular Expression for ISBN
Hi Friends,
I having an ISBN regular expression ISBN\x20(?=.{13}$)\d{1,5}( [- ])\d{1,7}\1\d{1,6}\1(\d|X) $
but it only matches to these three formats ISBN 0 93028 923 4,ISBN 1-56389-668-0
and ISBN 1-56389-016-X.
I found some serious like this ISBN 1847193579 and ISBN 13 978-1-847193-57-5.
So can anybody suggest a better expression?
Regards
I having an ISBN regular expression ISBN\x20(?=.{13}$)\d{1,5}(
but it only matches to these three formats ISBN 0 93028 923 4,ISBN 1-56389-668-0
and ISBN 1-56389-016-X.
I found some serious like this ISBN 1847193579 and ISBN 13 978-1-847193-57-5.
So can anybody suggest a better expression?
Regards
ASKER
Sorry ISBN[ -\d]+X? will not work. It will allow
"ISBN sds sdds 13 978-1-847193-57-5 ssdsd"
"ISBN sds sdds 13 978-1-847193-57-5 ssdsd"
* my solution:
ISBN[\x20\x2D]{0,1}(?:13[\ x20\x2D]{0 ,1}){0,1}( 978[\x20\x 2D]|979[\x 20\x2D]|)( ?=[0-9\x20 \x2D]{9,12 }[0-9xX]$) (\d{1,5}?) [\x20\x2D] {0,1}(\d{1 ,7})[\x20\ x2D]{0,1}( \d{1,6}?)[ \x20\x2D]{ 0,1}([0-9x X])$
* Short explanation:
1) match IBSN or IBSN 13 with/without hyphens/spaces, non-backreferencing
ISBN[\x20\x2D]{0,1}(?:13[\ x20\x2D]{0 ,1}){0,1}
2) first backreference group, \1, check for IBSN 13 prefix (978 or 979)
(978[\x20\x2D]|979[\x20\x2 D]|)
3) check length of remaining (max 9 digits + 1 digit or X, max 3 total punctuation (- or space) )
(?=[0-9\x20\x2D]{9,12}[0-9 xX]$)
4) second backreference, \2, 'group identifier' , i.e. language
(\d{1,5}?)[\x20\x2D]{0,1}
5) third backreference, \3, publisher
(\d{1,7})[\x20\x2D]{0,1}
6) fourth backreference, \4, item number
(\d{1,6}?)[\x20\x2D]{0,1}
7) final backreference, \5, checksum number
([0-9xX])
8) end of line / string
$
** Sample replacement string
ISBN 978-\2-\3-\4-\5
-- This will output any given IBSN in the 'new' 13 digit format. Although, if the ISBN is given as a string without punctuation, it will just make a reasonable guess on where the hyphens should be placed
ISBN[\x20\x2D]{0,1}(?:13[\
* Short explanation:
1) match IBSN or IBSN 13 with/without hyphens/spaces, non-backreferencing
ISBN[\x20\x2D]{0,1}(?:13[\
2) first backreference group, \1, check for IBSN 13 prefix (978 or 979)
(978[\x20\x2D]|979[\x20\x2
3) check length of remaining (max 9 digits + 1 digit or X, max 3 total punctuation (- or space) )
(?=[0-9\x20\x2D]{9,12}[0-9
4) second backreference, \2, 'group identifier' , i.e. language
(\d{1,5}?)[\x20\x2D]{0,1}
5) third backreference, \3, publisher
(\d{1,7})[\x20\x2D]{0,1}
6) fourth backreference, \4, item number
(\d{1,6}?)[\x20\x2D]{0,1}
7) final backreference, \5, checksum number
([0-9xX])
8) end of line / string
$
** Sample replacement string
ISBN 978-\2-\3-\4-\5
-- This will output any given IBSN in the 'new' 13 digit format. Although, if the ISBN is given as a string without punctuation, it will just make a reasonable guess on where the hyphens should be placed
> but it only matches to these three formats ISBN 0 93028 923 4,ISBN 1-56389-668-0
hmm, 1-56389-668-0 seems not to be a valid ISBN number should be 1-56389-668-11
So is your goal just to match the correct format or to verify if it is valid?
hmm, 1-56389-668-0 seems not to be a valid ISBN number should be 1-56389-668-11
So is your goal just to match the correct format or to verify if it is valid?
ISBN[ -\d]+X? will not match "ISBN sds sdds 13 978-1-847193-57-5 ssdsd", but it will match "ISBN " in this case. You could add a requirement for a minimum number of digits.
by Michael Ash:
ISBN\x20(?=.{13}$)\d{1,5}( [- ])\d{1,7}\1\d{1,6}\1(\d|X) $
ISBN\x20(?=.{13}$)\d{1,5}(
ASKER
hi
i want use this regular expression with javascript. So how can i use this expression
ISBN[\x20\x2D]{0,1}(?:13[\ x20\x2D]{0 ,1}){0,1}( 978[\x20\x 2D]|979[\x 20\x2D]|)( ?=[0-9\x20 \x2D]{9,12 }[0-9xX]$) (\d{1,5}?) [\x20\x2D] {0,1}(\d{1 ,7})[\x20\ x2D]{0,1}( \d{1,6}?)[ \x20\x2D]{ 0,1}([0-9x X])$
it is too wide
i want use this regular expression with javascript. So how can i use this expression
ISBN[\x20\x2D]{0,1}(?:13[\
it is too wide
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thank you.
It is working now :)
It is working now :)
ASKER
:)
ISBN[ -\d]+X?