ISBN-10
Match 10-digit ISBNs, allowing optional hyphens or spaces between groups.
Try it in RegexPro →Available in
JavaScript / ECMAScript code
const re = new RegExp("\\b(?:\\d[\\- ]?){9}[\\dXx]\\b", "g");
const input = "0-306-40615-2";
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"\b(?:\d[\- ]?){9}[\dXx]\b")
input_text = "0-306-40615-2"
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(`\b(?:\d[\- ]?){9}[\dXx]\b`)
input := `0-306-40615-2`
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
\b(?:\d[\- ]?){9}[\dXx]\b (flags: g)Raw source: \b(?:\d[\- ]?){9}[\dXx]\b
How it works
Examples
Input
0-306-40615-2Matches
0-306-40615-2
Input
0306406152Matches
0306406152
Input
080442957XMatches
080442957X
Common use cases
- •Book catalog imports
- •Library management systems
- •E-commerce product identifiers
- •Bibliographic data cleaning
Related patterns
ISBN-13
ValidationMatch 13-digit ISBNs starting with 978 or 979, with optional hyphens or spaces.
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.