1. 代码
    #include<string>
    #include<regex>
    #include <iostream>
    using namespace std;
    
    bool IsValidIP(const std::string& strIP)
    {
        std::string str="(((\\d{1,2})|(1\\d{1,2})|(2[0-4]\\d)|(25[0-5]))\\.){3}((\\d{1,2})|(1\\d{1,2})|(2[0-4]\\d)|(25[0-5]))(?=(\\b|\\D))";
        cout<<"str="<<str<<endl;
        std::regex regExpress(str);
        return std::regex_match(strIP, regExpress);
    }
    
    int main()
    {
        bool bRet=IsValidIP("127.0.0.1");
    	cout<<"bRet="<<bRet<<endl;
    	getchar();
        return 0;
    }

  2. msvc编译:

  3.  msvc运行结果:

返回值为true

5. mingw编译: 

6. mingw运行结果:

 

返回值为false。

总结mingw能编译c++正则表达式,但是mingw运行C++正则表达式不对。

 

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐