ISBN-13
Match 13-digit ISBNs starting with 978 or 979, with optional hyphens or spaces.
Try it in RegexPro →Available in
JavaScript / ECMAScript code
const re = new RegExp("\\b97[89][\\- ]?(?:\\d[\\- ]?){9}\\d\\b", "g");
const input = "978-0-306-40615-7";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).
Python (re) code
import re
pattern = re.compile(r"\b97[89][\- ]?(?:\d[\- ]?){9}\d\b")
input_text = "978-0-306-40615-7"
for m in pattern.finditer(input_text):
print(m.group(0))Stdlib `re` module — no third-party dependency. Works on Python 3.6+.
Go (RE2) code
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`\b97[89][\- ]?(?:\d[\- ]?){9}\d\b`)
input := `978-0-306-40615-7`
for _, match := range re.FindAllString(input, -1) {
fmt.Println(match)
}
}Uses `regexp.MustCompile` (panics on bad patterns at startup) and `FindAllString` for all matches.
Pattern
\b97[89][\- ]?(?:\d[\- ]?){9}\d\b (flags: g)Raw source: \b97[89][\- ]?(?:\d[\- ]?){9}\d\b
How it works
Examples
Input
978-0-306-40615-7Matches
978-0-306-40615-7
Input
9780306406157Matches
9780306406157
Common use cases
- •Modern book catalog validation
- •Retail inventory systems
- •Publisher metadata ingestion
- •ISBN format conversion pipelines
Related patterns
ISBN-10
ValidationMatch 10-digit ISBNs, allowing optional hyphens or spaces between groups.
Credit Card Number
ValidationMatch 16-digit credit card numbers with optional spaces or hyphens between groups of 4.
Alphanumeric Only
ValidationMatch strings containing only letters (A–Z, a–z) and digits (0–9), with no spaces or special characters.
International Phone (E.164)
ValidationValidate phone numbers in ITU-T E.164 international format: a + sign followed by 2–15 digits, first digit non-zero.