!43124 Fix ip regex

Merge pull request !43124 from ZPaC/optimize-ip-regex
This commit is contained in:
i-robot 2022-09-29 12:14:49 +00:00 committed by Gitee
commit c4f2e86de1
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
1 changed files with 2 additions and 4 deletions

View File

@ -38,10 +38,8 @@ std::uniform_int_distribution<> CommUtil::dis2 = std::uniform_int_distribution<>
bool CommUtil::CheckIpWithRegex(const std::string &ip) {
std::regex pattern(
"(25[0-4]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9])"
"[.](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])"
"[.](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])"
"[.](25[0-4]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9])");
"(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.)"
"{3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])");
std::smatch res;
if (regex_match(ip, res, pattern)) {
return true;