Regexp mysql function
I have several PHP regexes that I use to match ISBN 10, but I can't find one that is MySQL compatible REGEXP
, can anyone help me match ISBN 10 in MySQL?
I tried this one (works in PHP but not MySQL)
"^(97(8|9))?\d{9}(\d|X)$"
Here are some of the values I'm running for this regex:
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
+3
user1989379
source
to share
1 answer
The shortcut \d
does not exist in MySQL regular expressions. Use a character class instead [[:digit:]]
:
"^(97(8|9))?[[:digit:]]{9}([[:digit:]]|X)$"
Have a look at the sqlfiddle .
+3
eggyal
source
to share