문제

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
도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top