Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.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 如何使用正则表达式比较两个字符串_Regex_String_String Comparison - Fatal编程技术网

Regex 如何使用正则表达式比较两个字符串

Regex 如何使用正则表达式比较两个字符串,regex,string,string-comparison,Regex,String,String Comparison,我在MongoDB中有一个集合,其中包含如下URL列表 在一些需求的业务逻辑中,我想检查被调用的URL是否与DB记录中的任何记录匹配 我想,就像我得到的一样 /logistics/initiator/5ee7a0be36acdc46ae0576d6/users 但是在上面的URL中,我显然得到了实际的Id--5ee7a0be36acdc46ae0576d6 我的尝试: 我尝试手动将req.baseUrl和req.route.path连接起来,但仍然得到下面的字符串 /logistics/in

我在MongoDB中有一个集合,其中包含如下URL列表

在一些需求的业务逻辑中,我想检查被调用的URL是否与DB记录中的任何记录匹配

我想,就像我得到的一样

/logistics/initiator/5ee7a0be36acdc46ae0576d6/users
但是在上面的URL中,我显然得到了实际的Id--5ee7a0be36acdc46ae0576d6

我的尝试:

我尝试手动将req.baseUrl和req.route.path连接起来,但仍然得到下面的字符串

/logistics/initiator/:initiator/users

这也是不可比较的。

将ID替换为
\{\w+\}
,并将其用作正则表达式,以匹配表中的
url
列。因此regexp应该是
/logistics/initiator/\{\w+\}/users