Skip to content

Instantly share code, notes, and snippets.

@forcewake
Created June 5, 2015 12:55
Show Gist options
  • Save forcewake/82e4e646c41bb638a3db to your computer and use it in GitHub Desktop.
Save forcewake/82e4e646c41bb638a3db to your computer and use it in GitHub Desktop.
Getting content between curly braces in javascript regex
var found = [], // an array to collect the strings that are found
rxp = /{([^}]+)}/g,
str = "a {string} with {curly} braces",
curMatch;
while( curMatch = rxp.exec( str ) ) {
found.push( curMatch[1] );
}
console.log( found ); // ["string", "curly"]
@YashashGaurav
Copy link

["{string}", "{curly}"] - this is what I am getting as a response, I am still trying to figure out a rgx which would not include the curly braces.

@am
Copy link

am commented Oct 26, 2018

@YashashGaurav Hope by this time you found that in any case: rxp = /([^}]+)/g, should do what you are looking for

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment