isbn_findall#

isbn_findall(haystack, *, validate=True)#

Find all non-overlapping ISBNs in the given haystack.

This function searches for all non-averlapping ISBNs in the given haystack. By default, all ISBNs are validated (check digit verification); if invalid ISBNs are to be included as well, the validate flag must be set to False.

The underlying regular expression is based on the approach described in the book Regular Expressions Cookbook by Jan Goyvaerts and Steven Levithan [1]. It finds ISBNs in both the ISBN-10 and ISBN-13 formats. The individual components of an ISBN can be separated either by a space (SPACE U+0020) or a hyphen (HYPHEN-MINUS U+002D).

[1]

Jan Goyvaerts and Steven Levithan. O’Reilly, Beijing u.a., 2nd ed., ISBN 978-1-4493-1943-4, 2012, p. 292.

Added in version 0.3.0.

Warning

This functionality is considered unstable. It may be changed at any point without it being considered a breaking change.

Parameters:
haystackstr

The string to be searched.

validatebool, default=True

If set, the value found is verified to ensure that it is a formally valid ISBN.

Returns:
list[Match]

The list of all matches.

See also

isbn_find

Find the first ISBN in the given haystack.

Examples

>>> from marc21_learn.pid import isbn_findall
>>>
>>> haystack = "ISBN-13: 978-1-098-17130-8 ISBN-10: 1098171306"
>>> result = isbn_findall(haystack)
>>> assert len(result) == 2
>>> result[0]
Match(value: '978-1-098-17130-8', start: 9, end: 26)
>>> result[1]
Match(value: '1098171306', start: 36, end: 46)