Question

I have several PHP regex that I use for matching ISBN 10 but I can't find one that is compatible for MySQL's REGEXP, can someone help me match ISBN 10 in MySQL?

I have tried this one (works in PHP but not in MySQL)

"^(97(8|9))?\d{9}(\d|X)$"

Here are some values that I am running this regex against:

ISBN10: 0470945176
by Paul D. Kimmel
Publisher: John Wiley & Sons
Copyright year: © 2011

and

Thomas E. Creighton (Author)
ISBN-10: 0471153028 
Publisher: Wiley-Interscience; 1 edition (April 8, 1999)
2878 pages
Was it helpful?

Solution

The \d shortcut doesn't exist in MySQL regular expressions. Use the [[:digit:]] character class instead:

"^(97(8|9))?[[:digit:]]{9}([[:digit:]]|X)$"

See it on sqlfiddle.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top