Sponsored Content
Top Forums Shell Programming and Scripting help me create regexp for ISBN Post 302393967 by Lukasito on Wednesday 10th of February 2010 05:47:23 AM
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? :/
 

9 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

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. 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

7. 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

8. 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

9. What is on Your Mind?

A Regexp You Can Use Everywhere

¯\_(ツ)_/¯ bakunin (0 Replies)
Discussion started by: bakunin
0 Replies
Business::ISBN(3)					User Contributed Perl Documentation					 Business::ISBN(3)

NAME
Business::ISBN - work with International Standard Book Numbers SYNOPSIS
use Business::ISBN; # 10 digit ISBNs $isbn10 = Business::ISBN->new('1565922573'); $isbn10 = Business::ISBN->new('1-56592-257-3'); # 13 digit ISBNs $isbn13 = Business::ISBN->new('978-0-596-52724-2'); # convert $isbn10 = $isbn13->as_isbn10; # for the 978 prefixes $isbn13 = $isbn10->as_isbn13; # maybe you don't care what it is as long as everything works $isbn = Business::ISBN->new( $ARGV[0] ); #print the ISBN with hyphens at usual positions print $isbn->as_string; #print the ISBN with hyphens at specified positions. #this not does affect the default positions print $isbn->as_string([]); #print the group code or publisher code print $isbn->group_code; print $isbn->publisher_code; #check to see if the ISBN is valid $isbn->is_valid; #fix the ISBN checksum. BEWARE: the error might not be #in the checksum! $isbn->fix_checksum; # create an EAN13 barcode in PNG format $isbn->png_barcode; DESCRIPTION
This modules handles International Standard Book Numbers, including ISBN-10 and ISBN-13. Function interface valid_isbn_checksum( ISBN10 | ISBN13 ) This function is exportable on demand, and works for either 10 or 13 character ISBNs). use Business::ISBN qw( valid_isbn_checksum ); Returns 1 if the ISBN is a valid ISBN with the right checksum. Returns 0 if the ISBN has valid prefix and publisher codes, but an invalid checksum. Returns undef if the ISBN does not validate for any other reason. Object interface new($isbn) The constructor accepts a scalar representing the ISBN. The string representing the ISBN may contain characters other than "[0-9xX]", although these will be removed in the internal representation. The resulting string must look like an ISBN - the first nine characters must be digits and the tenth character must be a digit, 'x', or 'X'. The constructor attempts to determine the group code and the publisher code. If these data cannot be determined, the constructor sets "$obj->error" to something other than "GOOD_ISBN". An object is still returned and it is up to the program to check "$obj->error" for one of five values (which may be exported on demand). The actual values of these symbolic versions are the same as those from previous versions of this module which used literal values. Business::ISBN::INVALID_PUBLISHER_CODE Business::ISBN::INVALID_GROUP_CODE Business::ISBN::BAD_CHECKSUM Business::ISBN::GOOD_ISBN Business::ISBN::BAD_ISBN If you have one of these values and want to turn it into a string, you can use the %Business::ISBN::ERROR_TEXT hash, which is exportable by asking for it explicitly in the import list. use Business::ISBN qw(%ERROR_TEXT); The string passed as the ISBN need not be a valid ISBN as long as it superficially looks like one. This allows one to use the "fix_checksum()" method. Despite the disclaimer in the discussion of that method, the author has found it extremely useful. One should check the validity of the ISBN with "is_valid()" rather than relying on the return value of the constructor. If all one wants to do is check the validity of an ISBN, one can skip the object-oriented interface and use the "valid_isbn_checksum()" function which is exportable on demand. If the constructor decides it cannot create an object, it returns "undef". It may do this if the string passed as the ISBN cannot be munged to the internal format meaning that it does not even come close to looking like an ISBN. Instance methods input_isbn Returns the starting ISBN. Since you may insert hyphens or fix checksums, you might want to see the original data. common_data Returns the starting ISBN after normalization, which removes anything that isn't a digit or a valid checksum character. isbn Returns the current value of ISBN, even if it has an invalid checksum. This is the raw data so it doesn't have the hyphens. If you want hyphenation, try "as_string". The "isbn" method should be the same as "as_string( [] )". error Return the error code for the reason the ISBN isn't valid. The return value is a key in %ERROR_TEXT. is_valid Return true if the ISBN is valid, meaning that it has a valid prefix (for ISBN-13), group code, and publisher code; and its checksum validates. type Returns either "ISBN10" or "ISBN13". prefix Returns the prefix for the ISBN. This is currently either 978 or 979 for ISBN-13. It returns the empty string (so, a defined value) for ISBN-10. group_code Returns the group code for the ISBN. This is the numerical version, for example, '0' for the English group. The valid group codes come from "Business::ISBN::Data". group Returns the group name for the ISBN. This is the string version. For instance, 'English' for the '0' group. The names come from "Business::ISBN::Data". publisher_code Returns the publisher code for the ISBN. This is the numeric version, for instance '596' for O'Reilly Media. article_code Returns the article code for the ISBN. This is the numeric version that uniquely identifies the item. checksum Returns the checksum code for the ISBN. This checksum may not be valid since you can create an object an fix the checksum later with "fix_checksum". is_valid_checksum Returns "Business::ISBN::GOOD_ISBN" for valid checksums and "Business::ISBN::BAD_CHECKSUM" otherwise. This does not guarantee that the rest of the ISBN is actually assigned to a book. fix_checksum Checks the checksum and modifies the ISBN to set it correctly if needed. as_string(), as_string([]) Return the ISBN as a string. This function takes an optional anonymous array (or array reference) that specifies the placement of hyphens in the string. An empty anonymous array produces a string with no hyphens. An empty argument list automatically hyphenates the ISBN based on the discovered group and publisher codes. An ISBN that is not valid may produce strange results. The positions specified in the passed anonymous array are only used for one method use and do not replace the values specified by the constructor. The method assumes that you know what you are doing and will attempt to use the least three positions specified. If you pass an anonymous array of several positions, the list will be sorted and the lowest three positions will be used. Positions less than 1 and greater than 12 are silently ignored. A terminating 'x' is changed to 'X'. as_isbn10 Returns a new ISBN object. If the object is already ISBN-10, this method clones it. If it is an ISBN-13 with the prefix 978, it returns the ISBN-10 equivalent. For all other cases it returns undef. as_isbn13 Returns a new ISBN object. If the object is already ISBN-13, this method clones it. If it is an ISBN-10, it returns the ISBN-13 equivalent with the 978 prefix. xisbn In scalar context, returns an anonymous array of related ISBNs using xISBN. In list context, returns a list. This feature requires "LWP::Simple". png_barcode Returns image data in PNG format for the barcode for the ISBN. This works with ISBN-10 and ISBN-13. The ISBN-10s are automaically converted to ISBN-13. This requires "GD::Barcode::EAN13". BUGS
TO DO
* i would like to create the bar codes with the price extension SOURCE AVAILABILITY
This source is in Github: https://github.com/briandfoy/business--isbn AUTHOR
brian d foy "<bdfoy@cpan.org>" COPYRIGHT AND LICENSE
Copyright (c) 2001-2013, brian d foy, All Rights Reserved. You may redistribute this under the same terms as Perl itself. CREDITS
Thanks to Mark W. Eichin "<eichin@thok.org>" for suggestions and discussions on EAN support. Thanks to Andy Lester "<andy@petdance.com>" for lots of bug fixes and testing. Ed Summers "<esummers@cpan.org>" has volunteered to help with this module. perl v5.16.3 2013-05-31 Business::ISBN(3)
All times are GMT -4. The time now is 01:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy