我怎样才能匹配类似{anyWord}但排除开头有下划线的东西,如下所示:{_doNotMatchThis}?
输入:
hi there {matchPlease}{andThis}, just doing some regex {_notThis}
Run Code Online (Sandbox Code Playgroud)
期望的比赛:
{matchPlease}
{andThis}
Run Code Online (Sandbox Code Playgroud)
如果没有排除起点的条件{_,我知道这个正则表达式模式运行良好:\{\w+\}
我试图修改它\{!_\w+\},基本上是说,"匹配任何开头的东西{,然后有一个不能开头的单词_,然后结束}".谢谢.
这个怎么样?
/\{([^_].*?)\}/
Run Code Online (Sandbox Code Playgroud)
根据评论中的@Geo和@nhahhh,如果你只需要单词:
/\{([^_]\w*)\}/
Run Code Online (Sandbox Code Playgroud)