I have a file in which valid ISBNs always appear in the context of
isbn = {<ISBN>}
but often lack the dashes that are generally used for formatting them. I would like to insert these dashes using grep in BBEdit. For example I'd like to replace
isbn = {0226104036}
with
isbn = {0-226-10403-6}
but in order to do so I need to break up the string of digits, which requires ISBN encoding knowledge and grep skills I don't quite have.
I get as far as searching for
isbn = {([0-5]|7|60[0-9]|61[0-7]|8[0-9]|9[1-4]|9[5-8][0-9]|992[7-9]|99[3-8][0-9]|9990[1-9]|999[1-5][1-9]|9996[1-7])([0-9]+)([0-9]|X)}
and replace with
isbn = {\1-\2-\3}
which, in the above example, only gets me as far as
isbn = {0-22610403-6}
and might even put the first dash in the wrong place in some instances.
Note that I can assume that the ISBNs are all ISBN-10. Also note that I'm doing this in BBEdit, which has some grep syntax quirks. The related solutions I've found here either fail in BBEdit, or I can't adapt them to this particular scenario.