Tag:regex
-
To solve the problem of high CPU utilization of Mongo database caused by regular expression matching ($regex)
One day, it was monitored that the CPU utilization rate of Mongo database was much higher. After checking, it was found that it was caused by the following statements: db.example_collection.find({ “idField” : { “$regex” : “123456789012345678” } , “dateField” : { “$regex” : “2019/10/10” }}) Usually, when I encounter this situation, my first reaction is […]
-
Regular expression (regex) or operator “|” use bug prone function
Next: the misuse of regex leads to functional vulnerabilities. We continue to sort out that the misuse of regex leads to functional design vulnerabilities. We need to master a lot of knowledge to do web work. The work of website development has been in China for more than 10 years. Many developers are trained (self-study) […]
-
How to use greedy mode and lazy mode of regular expression (regex)
Regular expression greedy matching pattern, for beginners, it is also easy to make mistakes. Sometimes you need to match the content of a piece of code, and find that the match is inconsistent with what you want. It turns out that it has something to do with the greedy model. Here is an example: What […]
-
Using regex_replace to simulate reading INI files
No more nonsense, just paste code for you, the specific code is as follows: #include “stdio.h” #include <sstream> #include <iostream> #include <fstream> #include <regex> using namespace std; void Trim(char * str); void lTrim(char * str); void rTrim(char * str); // Testing sscanf and regular expressions // This extension provided by sscanf can’t really be called […]
-
Quickly grasp several uses of regex in MongoDB in 3 minutes
background Part1: Write at the top Friends who use MySQL or other relational databases know that the use of fuzzy queries is similar to: SELECT * FROM products WHERE sku like “%789”; The regex in MongoDB introduced in this article implements similar functions. Regex is designed to enable you to use regular expressions in queries. […]