help me create regexp for ISBN


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help me create regexp for ISBN
# 1  
Old 02-10-2010
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 :/

can you help?

also, can you tell me, in what reason doesnt my regex work? :/
# 2  
Old 02-10-2010
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
Quote:
Originally Posted by Lukasito
also, can you tell me, in what reason doesnt my regex work? :/
# 3  
Old 02-10-2010
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

Last edited by Lukasito; 02-10-2010 at 01:43 PM..
# 4  
Old 02-10-2010
I hate to quote my own posts, but apparently it's necessary sometimes:
Quote:
Originally Posted by pludi
You might have some success using 'grep -E' or egrep if available.
# 5  
Old 02-10-2010
Quote:
Originally Posted by Lukasito
i tried something like this:
Code:
[0-9]{0,3}[- ]{0,1}[0-9]{1,5}[- ]{1}[0-9]{0,7}[- ]{1}[0-9]{0,6}[- ]{1}[0-9X]{1}

Hi, I think this regex would be a bit more accurate:
Code:
(97[89][- ]){0,1}[0-9]{1,5}[- ][0-9]{1,7}[- ][0-9]{1,6}[- ][0-9X]


Last edited by Scrutinizer; 02-10-2010 at 05:52 PM..
# 6  
Old 02-10-2010
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
tip78
# 7  
Old 02-11-2010
Quote:
Originally Posted by Scrutinizer
Hi, I think this regex would be a bit more accurate:
Code:
(97[89][- ]){0,1}[0-9]{1,5}[- ][0-9]{1,7}[- ][0-9]{1,6}[- ][0-9X]


Thanks a lot...yop you're right, it is more accurate...mine was just only for ISBN10, thanks Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. What is on Your Mind?

A Regexp You Can Use Everywhere

¯\_(ツ)_/¯ bakunin (0 Replies)
Discussion started by: bakunin
0 Replies

2. Shell Programming and Scripting

Regexp

I would like to extract "1333 Fairlane" given the below text. The word "Building:" is always present. The wording between Building and the beginning of the address can be almost anything. It appears the the hyphen is there most of the time. Campus: Fairlane Business Park Building:... (9 Replies)
Discussion started by: bbaker@copesan.
9 Replies

3. Shell Programming and Scripting

help with grep regexp

My input file looks like this: 13154|X,the deer hunter 13154|Y,the good life 1316|,american idol 1316|,bowling 1316|,chuck etc... The X, Y, or any other character (besides a comma) after the pipe is a "Device Type". I want to strip out lines that do not have a device type. I have... (2 Replies)
Discussion started by: jwinsk
2 Replies

4. UNIX for Dummies Questions & Answers

print the line immediately after a regexp; but regexp is a sentence

Good Day, Im new to scripting especially awk and sed. I just would like to ask help from you guys about a sed command that prints the line immediately after a regexp, but not the line containing the regexp. sed -n '/regexp/{n;p;}' filename What if my regexp is 3 word or a sentence. Im... (3 Replies)
Discussion started by: ownins
3 Replies

5. Shell Programming and Scripting

Help with regexp

Hi there! I would like to know how to find and replace all numbers in a *.html file and make them bold. Any help will be appreciated! :) (7 Replies)
Discussion started by: agasamapetilon
7 Replies

6. Shell Programming and Scripting

regexp help

I'd like to know if there is a catchall line for renaming the following patterns: s01e03 -> 01x03 s4e9 -> 04x09 s10e08 ->10x08 and possibly even: 318 -> 03x18 1002 ->10x02 if its the first 3 or first digit number in the string. thanks! (0 Replies)
Discussion started by: TinCanFury
0 Replies

7. Shell Programming and Scripting

puzzling regexp

hey guys, i'm having some problems with my understanding of this whole regexp thing. I'm just exploring here really by trying to do various match & filter & print stuff on the console. I figured i want to get the IP of an interface. So my idea here was that first i filter to extract only... (4 Replies)
Discussion started by: jad
4 Replies

8. Shell Programming and Scripting

regexp assistance

i have a list of text a b c d e My desired output is 'a','b','c','d','e' any advise? My file was actually in excel format, i copied out the column into notepad. I am not sure if the \n exists in between. (2 Replies)
Discussion started by: new2ss
2 Replies

9. UNIX for Advanced & Expert Users

regexp

Hi guys, does anyone know how to test for a regular expression - i want to include it in a script to make sure the variable is a regexp cheers (1 Reply)
Discussion started by: penfold
1 Replies
Login or Register to Ask a Question