
Hi, we need to validate ISBN. With another REGEX-implementation we uses (?=.{13})\d{1,5}( |\-)\d{1,7}\1\d{1,6}\1(\d|X). But this seem not to work. Only the shorter version "\d{1,5}( |\\-)?\\d{1,7}\\1\\d{1,6}\\1(\d|X)" works, but how to check the 13 digits? Thanx in advanced Detlef

On Mon, 4 Apr 2005 10:05:52 +0200, Detlef wrote
Hi,
we need to validate ISBN. With another REGEX-implementation we uses (?=.{13})\d{1,5}( |\-)\d{1,7}\1\d{1,6}\1(\d|X). But this seem not to work. Only the shorter version "\d{1,5}( |\\-)?\\d{1,7}\\1\\d{1,6}\\1(\d|X) " works, but how to check the 13 digits?
I didn't try to figure out why this isn't working, but you might have a look at the site below -- it has a few examples of regex'es for ISBN validation: http://regexlib.com/Search.aspx?k=ISBN HTH, Jeff

In case your next question is how to check the number of a credit card is valid, I doubt if you can do this with regex, but I DO have some C++ code to check both ISBN and Credit cards, and most other protocols of this type. In fact I wonder if there is any interest in these as a Boost library? Paul Paul A Bristow Prizet Farmhouse, Kendal, Cumbria UK LA8 8AB +44 1539 561830 +44 7714 330204 mailto: pbristow@hetp.u-net.com | -----Original Message----- | From: boost-bounces@lists.boost.org | [mailto:boost-bounces@lists.boost.org] On Behalf Of Jeff Garland | Sent: 09 April 2005 15:24 | To: boost@lists.boost.org | Subject: Re: [boost] Regex-User: ISBN validation | | On Mon, 4 Apr 2005 10:05:52 +0200, Detlef wrote | > Hi, | > | > we need to validate ISBN. | > With another REGEX-implementation we uses (?=.{13})\d{1,5}( | > |\-)\d{1,7}\1\d{1,6}\1(\d|X). | > But this seem not to work. | > Only the shorter version "\d{1,5}( | |\\-)?\\d{1,7}\\1\\d{1,6}\\1(\d|X) | > " works, but how to check the 13 digits? | | I didn't try to figure out why this isn't working, but you | might have a look | at the site below -- it has a few examples of regex'es for | ISBN validation: | | http://regexlib.com/Search.aspx?k=ISBN | | HTH, | | Jeff | _______________________________________________ | Unsubscribe & other changes: | http://lists.boost.org/mailman/listinfo.cgi/boost |

but I DO have some C++ code to check both ISBN and Credit cards, and most other protocols of this type.
In fact I wonder if there is any interest in these as a Boost library?
Yes (perhaps you could list all the protocols). I'd expect they'd be quicker than using regexes, self-documenting (E.g. "boost::validate::credit_card(cc)" is more readable than "^\d{4}-?\d{4}-?\d{4}-?\d{2,4}$"), and also more accurate (I believe credit cards have meaning to the numbers that can also be validated). Darren

On Apr 11, 2005 7:13 PM, Darren Cook <darren@dcook.org> wrote:
but I DO have some C++ code to check both ISBN and Credit cards, and most other protocols of this type.
In fact I wonder if there is any interest in these as a Boost library?
Yes (perhaps you could list all the protocols).
I'd expect they'd be quicker than using regexes, self-documenting (E.g. "boost::validate::credit_card(cc)" is more readable than "^\d{4}-?\d{4}-?\d{4}-?\d{2,4}$"), and also more accurate (I believe credit cards have meaning to the numbers that can also be validated).
A boost::validate::date (and time and date_time) would be nice to have too. Also perhaps ::email and ::url (these would only test for syntactic validity, not resolving). It might make sense to provide a collection of "user-input" validation routines in one place like this. -- Caleb Epstein caleb dot epstein at gmail dot com

| -----Original Message----- | From: boost-bounces@lists.boost.org | [mailto:boost-bounces@lists.boost.org] On Behalf Of Darren Cook | Sent: 12 April 2005 00:14 | To: boost@lists.boost.org | Subject: Re: [boost] Regex-User: ISBN validation | | > but I DO have some C++ code to check both ISBN and Credit cards, | > and most other protocols of this type. | > | > In fact I wonder if there is any interest in these as a | Boost library? | | Yes (perhaps you could list all the protocols). Credit card, ISBN, EAN,and UPC codes, but can be quite general methods, so you could devise similar error detection and correction for arbitrary radix. // Version of check used by Mastercard, VISA, and most other credit card companies, // to allow radix (or base) other than 10, for example 32, 36 and 64. // Version using permutations devised by Joseph A. Gallian, // University of Minnesota, Duluth, USA. // Permutations Copyright Joseph A. Gallian 2002. // Copyright Paul A Bristow, 2002. // See Error Detection Methods, Joseph A. Gallian, // ACM computing Surveys, 28(3) 504-517 (Sep 1996) // ISSN 0360-0300 // J A Gallian & S Winters, (1988), Amer. Math. Monthly 95, 548-551. // A. Ecker & G. Poch, Check Character system, Computing, 37, 277-301 (1986) // The characters representing the digit values may be assigned arbitrarily // using a lookup table, for example using code similar to // Gene Callahan, Dr Dobb's Journal, Dec 1995, 131, 132 & 149. // Generating Sequential keys in an Arbitrary Radix. // For example, a radix 42 (Douglas Admas's Memorial) might use the following // "0123456789abcdefghijklmnopqrstuvwxyz!#$%&~" // to represent integer values from 0,1,2 ... 40,41 where, for example, // 0 is represented by '0', 9 by '9', 15 by 'f', ... 40 by '&' and 41 by '~' // Some letters might be omitted to avoid confusion with digits ('0' and 'O') // and to reduce the risk of offensive words appearing. Of course, there is endless scope for argument about the presentation of these functions. (Templated versions for char, wide char, short int ...?) So I am reluctant to embark on Boostification unless there is serious interest. I would have thought it would be useful for many applications, but then Boost seems to be concentrating on more fundamental 'concepts'. Paul Paul A Bristow Prizet Farmhouse, Kendal, Cumbria UK LA8 8AB +44 1539 561830 +44 7714 330204 mailto: pbristow@hetp.u-net.com

we need to validate ISBN. With another REGEX-implementation we uses (?=.{13})\d{1,5}( |\-)\d{1,7}\1\d{1,6}\1(\d|X). But this seem not to work. Only the shorter version "\d{1,5}( |\\-)?\\d{1,7}\\1\\d{1,6}\\1(\d|X)" works, but how to check the 13 digits?
It certainly should work, but can you: 1) Check that if you are embedding the regex in the program as a string, that you have "double escaped" any escape characters that should be seen by the regex engine (remember that the C++ compiler swallows the first one). 2) Can you provide a short test case of something you think you should work but doesn't. Thanks, John.

Detlef wrote:
we need to validate ISBN. With another REGEX-implementation we uses (?=.{13})\d{1,5}( |\-)\d{1,7}\1\d{1,6}\1(\d|X). But this seem not to work. Only the shorter version "\d{1,5}( |\\-)?\\d{1,7}\\1\\d{1,6}\\1(\d|X)" works, but how to check the 13 digits?
Have you tried \2 instead of \1 for the long expression? AFAICS from the documentation <http://www.boost.org/libs/regex/doc/syntax.html>, the first "Forward Lookahead Assert" is still a match, but you want to refer to the second parenthesis, right? Regards, Daniel

Have you tried \2 instead of \1 for the long expression? AFAICS from the documentation <http://www.boost.org/libs/regex/doc/syntax.html>, the first "Forward Lookahead Assert" is still a match, but you want to refer to the second parenthesis, right?
I don't think so: $2 appears after the last backreference, so would be an invalid expression, (forward lookahead asserts don't count as marked sub-expressions - nothing that begins (? does ). John.
participants (7)
-
Caleb Epstein
-
Daniel Frey
-
Darren Cook
-
Detlef
-
Jeff Garland
-
John Maddock
-
Paul A Bristow