Just looking to see how I would make this function more efficient.
I’m a beginner programmer building my first chrome extension. It scans webpages for ISBN-13s and DOIs and searches another site to see if they are available for download. There can’t be any special characters though, so I have to clean out any “-” that commonly show up. This is the match / cleanup function.
Is there any way that I could do this better? The “-” sliceout seems particularly wieldy. I know how to do that a bit faster in python, but I’m a lot less familiar with Javascript methods.
function isbn13extract(page) {
var isbn13pattern = /(978|979)[0-9|-]{10,11}/
var match = page.match(isbn13pattern)
matchout = match[0]
if(matchout[3] == "-")
matchout = matchout.substr(0,3) + matchout.substr(4,13)
console.log(matchout)
if (matchout != null) {
console.log("You did it this is the ISBN:", matchout)
return matchout
}
else {
console.log("Couldn't Find ISBN")
return(null)
}
}
I tried looking up if there were simpler methods to remove specific characters from strings in Javascript but what I mostly got were somewhat wieldy answers. The code currently runs though so what I am doing is working.