Skip to content

Instantly share code, notes, and snippets.

@jamesmacfie
Created December 21, 2014 18:54
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 jamesmacfie/8a0a7280f91179861710 to your computer and use it in GitHub Desktop.
Save jamesmacfie/8a0a7280f91179861710 to your computer and use it in GitHub Desktop.
A small .js regex to get a string between two characterse
// 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