-
-
Save wacoom/6ed17c0da705d995f8001ffada724e59 to your computer and use it in GitHub Desktop.
Extract substring between two strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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