Reputation: 422
i have the following regular expression to use for ISBN-10
^[0-9]{9}[[0-9]|X|x]$^
it seems to work fine with all numbers, however when letters are introduced it gives me the letter instead, example ISBN 047146158X returns X in the array,
can someone help me with my expression?
this is what the data looks like
startISBN 10-047146158X Author(s): Stephen R. Bolsover, Jeremy S. Hyams, Elizabeth A. Shephard, Hugh A. White, Claudia G. Wiedemann Publisher- Wiley 27 JAN 2004
Upvotes: 1
Views: 337
Reputation: 33163
Either
[0-9]{9}([0-9]|X|x)
or just
[0-9]{9}[0-9Xx]
The []
brackets match a single character inside them, nesting them doesn't do what you want. Parentheses ()
mark a group where you can use the |
character to separate different options, but since you're looking for one character only you can just put everything in brackets.
^
means "start of line" and $
means "end of line" - if you have them at the start and at the end, the regex matches only if there's nothing else in the input.
Upvotes: 2