简体   繁体   English

有人可以告诉我如何阅读以下内容:/\\.(js)$/

[英]Can someone please tell me how to read the following: /\.(js)$/

I'm trying to understand some webserver code I found online and the part right after the "else if" is the only part I don't understand. 我试图了解一些我在网上找到的网络服务器代码,而“ else if”之后的部分是我唯一不了解的部分。 (I just started learning this stuff). (我刚刚开始学习这些东西)。 Thanks 谢谢

 var path = url.parse(req.url).pathname; // Managing the root route if (path == '/') { index = fs.readFile(__dirname+'/public/index.html', function(error,data) { //do stuff... }); // Managing the route for the javascript files } else if( /\\.(js)$/.test(path) ) { index = fs.readFile(__dirname+'/public'+path, function(error,data) { //do stuff... }); 

It allows you to test against regular expresions. 它使您可以针对常规表达式进行测试。 Heres the MDN on how it works. 这是MDN的工作原理。

In your example, it's checking if the path ends in .js 在您的示例中,它正在检查路径是否以.js结尾

Regular expressions produce non strict match against the string. 正则表达式对字符串产生非严格匹配。 Besides MSDN @SpeedOfRound mentioned about it would be useful to play with this service to get the better understanding on your exact case 除了提到的MSDN @SpeedOfRound之外,使用此服务有助于更好地了解您的实际情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM