help me create regexp for ISBN

ISBN 10:
it has 4 groups separated with ' ' or '-'

  1. group need to has 1-5 digits
  2. group need to has max 7
  3. max 6
  4. 1 digit or letter 'X'

ISBN 13
5 groups separated with ' ' or '-'

  1. group - always has 3 digits
  2. group same as 1st in isbn10
  3. group same as 2nd in isbn10
  4. group same as 3rd in isbn10
  5. group same as 4th in isbn10

i need to construct regexp which can match ISBN10 OR ISBN13

i tried something like this:
[0-9]{0,3}[- ]{0,1}[0-9]{1,5}[- ]{1}[0-9]{0,7}[- ]{1}[0-9]{0,6}[- ]{1}[0-9X]{1}
but it works only on regextester.com not in my grep -o command :confused:

can you help?

also, can you tell me, in what reason doesnt my regex work? :confused:

The reason is that the mentioned Regex tester supports PCREs (Perl Compatible Regular Expressions) while regular grep does not. You might have some success using 'grep -E' or egrep if available.

And what do you mean by

you've already answer your question

anyway...so is my regexp correct? Or can you modify it to works with grep?

// I guess i've solve it... the -E param helps

I hate to quote my own posts, but apparently it's necessary sometimes:

Hi, I think this regex would be a bit more accurate:

(97[89][- ]){0,1}[0-9]{1,5}[- ][0-9]{1,7}[- ][0-9]{1,6}[- ][0-9X]

better if you will post a complete text line which you need to cut
then post the line which you expect to get as result of regexp

Thanks a lot...yop you're right, it is more accurate...mine was just only for ISBN10, thanks :slight_smile: