Login  Register

Re: Can it do this way ?

Posted by Steffen Märcker on Sep 07, 2020; 8:14pm
URL: https://forum.world.st/Can-it-do-this-way-tp5121193p5121434.html

Now having a Workspace at hand, I fixed some minor typos:

IsbnVarifier>>isSyntacticIsbn: aString
   | nonGrouped dashes spaces grouped |
   nonGrouped := '\d{9}[0-9X]' asRegex.
   "groups separated by either dashes or spaces"
   dashes := '\d{1,7}-\d{1,7}-\d{1,7}-[0-9X]'.
   spaces := '\d{1,7} \d{1,7} \d{1,7} [0-9X]'.
   grouped := (dashes , '|' , spaces) asRegex.
   ^(aString matchesRegex: nonGrouped) or:
     [(aString matchesRegex: grouped) and:
       [aString size = (10 + 3)]]

Best, Steffen


Am .09.2020, 19:01 Uhr, schrieb Steffen Märcker <[hidden email]>:

> Hi,
>
> after reading the link and some additional sources, it turns out that a
> valid ISBN-10 has either no separators or four blocks separated by either
> dashes or spaces:
>    Group-Publisher-Title-CheckDigit
>
> Assuming Regex11 (and that I made no mistake), the following should do  
> the
> trick:
>
> IsbnVarifier>>isSyntacticIsbn: aString
>    "no groups"
>    noGrouped := '\d{9}[0-9X]' asRegex.
>    "groups separated by either dashes or spaces"
>    dashes := '\d{1,7}-\d{1,7}-\d{1,7}-[0-9X]'
>    spaces := '\d{1,7} \d{1,7} \d{1,7} [0-9X]'
>    grouped := (dashed , '|' , spaces) asRegex.
>
>    ^(aString matches: nonGrouped) or:
>      [(aString matches: grouped) and:
>        [aString size = 10 + 3]]
>
> Surely, you could cleverly compress the regex even further but that does
> not matter for this example. After checking the syntax, you can just
> iterate over the string and compute the check-digit on the fly.
>
> Kind regards,
> Steffen
>
> Am .09.2020, 18:19 Uhr, schrieb Roelof Wobben via Pharo-users
> <[hidden email]>:
>
>> See here for all the tests :
>> https://github.com/exercism/pharo-smalltalk/blob/master/exercises/isbn-verifier/IsbnVerifierTest.class.st#L88
>>
>> Roelof
>>
>>
>>