Skip to content

Instantly share code, notes, and snippets.

@snewcomer
Created March 22, 2019 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save snewcomer/43d7286f588b4d38ac37f25374ca1fc0 to your computer and use it in GitHub Desktop.
Save snewcomer/43d7286f588b4d38ac37f25374ca1fc0 to your computer and use it in GitHub Desktop.
matching line
const removeMatchingLine = (str, match) => {
let index = str.indexOf(match);
// If it is not found, return str
if (index === -1) {
return str;
}
// Look for the previous line feed
let start = index;
while(str.charAt(start) !== "\n") {
start--;
}
start++;
// Look for next by line feed
let end = index + match.length + 1;
while(str.charAt(end) !== "\n") {
end++;
}
end++;
return str.substring(0, start) + str.substring(end);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment