Regular Expression Guidance needed for Javascript

In the following input string: {$foo}foo bar \\{$blah1}oh{$blah2} even more{$blah3} but not{$blarg}{$why_not_me} I am trying to match all instances of `{$SOMETHING_HERE}` that are not preceded by an unescaped backslash. **Example:** I want it to match `{$SOMETHING}` but not `\{$SOMETHING}`. But I do want it to match `\\{$SOMETHING}` **Attempts:** All of my attempts so far will match what I want except for tags right next to each other like `{$SOMETHING}{$SOMETHING_ELSE}` Here is what I currently have: var input = '{$foo}foo bar \\{$blah1}oh{$blah2} even more{$blah3} but not{$blarg}{$why_not_me}'; var results = input.match(/(?:[^\\]|^)\{\$[a-zA-Z_][a-zA-Z0-9_]*\}/g); console.log(results); Which outputs: ["{$foo}", "h{$blah2}", "e{$blah3}", "t{$blarg}"] **Goal** I want it to be : ["{$foo}", "{$blah2}", "{$blah3}", "{$blarg}", "{$why_not_me}"] **Question** Can anybody point me in the right direction?

以上就是Regular Expression Guidance needed for Javascript的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准