Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex nodejs中正则表达式中的特定名称除外_Regex_Node.js - Fatal编程技术网

Regex nodejs中正则表达式中的特定名称除外

Regex nodejs中正则表达式中的特定名称除外,regex,node.js,Regex,Node.js,我想传递除NodeJs的/employers/in-app.get()之外的所有URL。我写了以下内容,但没有成功 app.get('/(!employers)/*', function(req, res, next) { // COME HERE EXCEPT EMPLOYERS }); 试试这个 app.get(/^((?!employers).)*$/, function(req, res, next) { // COME HERE EXCEPT EMPLOYERS });

我想传递除NodeJs的/employers/in-app.get()之外的所有URL。我写了以下内容,但没有成功

app.get('/(!employers)/*', function(req, res, next) {
   // COME HERE EXCEPT EMPLOYERS
});
试试这个

app.get(/^((?!employers).)*$/, function(req, res, next) {
   // COME HERE EXCEPT EMPLOYERS
});

Simple
如果
indexOf
的条件足够,则不需要正则表达式
If(url.indexOf('employers')!=-1{}
我不想在app.get()之后再上一层楼。我想在应用程序中添加。获取(…..)级别。尝试此正则表达式-^((?!employers)。*$@HarpreetSingh您可以发布为答案吗?是的,但它是否按预期工作?为了只匹配,您可以使组不捕获:
(?:(!employers)。*$
,但为什么要使用正则表达式呢?在这种情况下,字符串函数会快得多。