如何在Express.js中创建"不以......开头"的正则表达式?

TIM*_*MEX 1 regex node.js express

app.get('if it does not begin with /api', function(req,res){
    //the path does not begin with "/api"
});
Run Code Online (Sandbox Code Playgroud)

我怎么写那个正则表达式?

Ser*_*gio 6

您应该在JavaScript中使用正常的正则表达式,具有负前瞻性.试试这个:

app.get(/^(?!\/api).+/, function(req,res){
    //the path does not begin with "/api"
});
Run Code Online (Sandbox Code Playgroud)