package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?mi)(?=.*(?:epub|digital|e-?(?:ISBN|book))).*ISBN(?: *13)?:?\s+\K(\d(?:-?\d){12})`)
var str = `These should match to indicate they are eBook ISBNs:
ISBN 978-1-9821-8584-8 (ebook)
EISBN: 9781101487280
eISBN: 978-1-4406-3132-0
eISBN 9781429902304
Ebook ISBN: 9780593547342
eBook ISBN: 9780804139038
e-ISBN 978-0-765-37686-2
Digital Edition MAY 2017 ISBN: 978-0-06-244198-0
ISBN 13: 978-0-9999999-9-9 (eBook edition)
EPub © Edition JUNE 2003 ISBN: 9780061739200
But then these should not match, as they are assumbed to be print copy ISBNs:
Print ISBN: 978-0-06-244197-3
ISBN 978-1-9821-8582-4
ISBN 9780804139021
ISBN-13: 978-1-4299-6030-4
ISBN 13: 978-0-9999999-9-9 (Paperback edition)`
for i, match := range re.FindAllString(str, -1) {
fmt.Println(match, "found at index", i)
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Golang, please visit: https://golang.org/pkg/regexp/