Skip to content

Instantly share code, notes, and snippets.

@otiai10
Created November 11, 2013 08:33
Show Gist options
  • Save otiai10/7409798 to your computer and use it in GitHub Desktop.
Save otiai10/7409798 to your computer and use it in GitHub Desktop.
regex in javascript
var re = new RegExp("\\{\\{if " + "hoge" + "\\}\\}(.*)\\{\\{\\/if\\}\\}", "g");
var str = "前 {{if hoge}}ここはifの中{{/if}}あと";
console.log(re.exec(str));
/*
[ '{{if hoge}}ここはifの中{{/if}}',
'ここはifの中',
index: 2,
input: '前 {{if hoge}}ここはifの中{{/if}}あと' ]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment