Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

regexp mysql function

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
like image 538
user1989379 Avatar asked May 27 '26 15:05

user1989379


1 Answers

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.

like image 97
eggyal Avatar answered May 30 '26 05:05

eggyal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!