Make use of regular expressions in title processing more effective. (#959)
diff --git a/Readability.js b/Readability.js index 5c8ee0b..ad32a65 100644 --- a/Readability.js +++ b/Readability.js
@@ -595,11 +595,12 @@ // If there's a separator in the title, first remove the final part if (/ [\|\-\\\/>»] /.test(curTitle)) { titleHadHierarchicalSeparators = / [\\\/>»] /.test(curTitle); - curTitle = origTitle.replace(/(.*)[\|\-\\\/>»] .*/gi, "$1"); + let allSeparators = Array.from(origTitle.matchAll(/ [\|\-\\\/>»] /gi)); + curTitle = origTitle.substring(0, allSeparators.pop().index); // If the resulting title is too short, remove the first part instead: if (wordCount(curTitle) < 3) { - curTitle = origTitle.replace(/[^\|\-\\\/>»]*[\|\-\\\/>»](.*)/gi, "$1"); + curTitle = origTitle.replace(/^[^\|\-\\\/>»]*[\|\-\\\/>»]/gi, ""); } } else if (curTitle.includes(": ")) { // Check if we have an heading containing this exact string, so we