node.js - MongoDB RegExp inconsistency -


यहां टेस्ट केस है:

  db.test.insert ({name: "john "}); Db.test.insert ({name: "donny"}); Db.test.insert ({name: "lenny"}); db.test.find ({name: {$ regex: / ^ ((?! एनएन) [\ s \ S]) * $ /}}); // काम ठीक है, केवल जॉन db.test.find लौटाता है ({name: {$ regex: new RegExp ("/ ^ ((?! nn) [\ s \ s]) * $ /")}}); // कुछ भी रिटर्न नहीं देता   

रिजक्स को उन वस्तुओं को वापस करना माना जाता है जो कि "एनएन" को कंटैसिंग नहीं कर रहे हैं, लेकिन यह RegExp ऑब्जेक्ट का उपयोग करते समय काम नहीं करता है।

इसमें शामिल न करें new RegExp का उपयोग करते समय अग्रणी और पीछे वाले / वर्ण। उनको केवल जावास्क्रिप्ट में शाब्दिक अंकन के साथ प्रयोग किया जाता है आपको अपने बैकस्लैश स्ट्रिंग में से बचने की भी आवश्यकता है।

  db.test.find ({name: {$ regex: new RegExp ("^ ((?! nn) [\\ s \ \ एस]) * $ ")}});    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -