Skip to content

Instantly share code, notes, and snippets.

@wacoom
Forked from GuillaumeJasmin/extract.js
Created December 14, 2020 04:42
Show Gist options
  • Save wacoom/6ed17c0da705d995f8001ffada724e59 to your computer and use it in GitHub Desktop.
Save wacoom/6ed17c0da705d995f8001ffada724e59 to your computer and use it in GitHub Desktop.
Extract substring between two strings
String.prototype.extract = function(prefix, suffix) {
s = this;
var i = s.indexOf(prefix);
if (i >= 0) {
s = s.substring(i + prefix.length);
}
else {
return '';
}
if (suffix) {
i = s.indexOf(suffix);
if (i >= 0) {
s = s.substring(0, i);
}
else {
return '';
}
}
return s;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment