Last active
September 26, 2022 04:10
-
-
Save GuillaumeJasmin/9119436 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; | |
}; |
Bless your soul!
cool !
u rock
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What about multiple matches?