Created
December 21, 2014 18:54
-
-
Save jamesmacfie/8a0a7280f91179861710 to your computer and use it in GitHub Desktop.
A small .js regex to get a string between two characterse
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
// Example usage | |
"This is my {string}".match(/{(.*)}/).pop(); // string | |
// Example function | |
function extractString(string, startChar, endChar) { | |
var re = new RegExp([startChar, '(.*)', endChar].join('')); | |
return string.match(re); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment