boost regex 数据有效性检测

头文件:
 

#ifndef __VALIDFILTER__H
#define __VALIDFILTER__H

#define VALIDFILTER_FLOATNUM            "([0-9]+).([0-9]+)|([0-9]+)"
#define VALIDFILTER_FLOAT                "([0-9]+).([0-9]+)"
#define VALIDFILTER_NUM                "[0-9]+"
#define VALIDFILTER_ALPHABET            "[a-z]+"
#define VALIDFILTER_                    ""

#include <iostream>
#include <boost/regex.hpp>
using namespace boost;
using namespace std;

class validfilter
{
public:
    validfilter(void);
    ~validfilter(void);

    bool IsFloatAndNum( std::string value);
    bool IsFloat( std::string value);
    bool IsNum( std::string value);
    bool IsAlphabet( std::string value);

private:
    bool validmatch( std::string& value,std::string regex_expression);

};

#endif


.cpp

#include "validfilter.h"

using namespace boost;
using namespace std;

validfilter::validfilter(void)
{

}

validfilter::~validfilter(void)
{

}


bool validfilter::IsFloatAndNum( std::string value)
{
    return validmatch( value,VALIDFILTER_FLOATNUM);
}

bool validfilter::IsFloat( std::string value)
{
    return validmatch( value,VALIDFILTER_FLOAT);    
}

bool validfilter::IsNum( std::string value)
{
    return validmatch( value,VALIDFILTER_NUM);    
}

bool validfilter::IsAlphabet( std::string value)
{
    return validmatch( value,VALIDFILTER_ALPHABET);
}

bool validfilter::validmatch( std::string& value,std::string regex_expression)
{
    if( value.empty() || regex_expression.empty() )
        return false;

    boost::regex expression(regex_expression);

    if( regex_match( value,expression)) //字符串匹配

    {
        return true;
    }
    else
    {
        return false;
    }

}


demo测试程序

 


#include <iostream>
#include <stdio.h>
#include "validfilter.h"

using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{
    validfilter filter;
    bool state;
    std::string str;

    while(1)
    {
        cout<<"input:"<<endl;
        cin>> str;

        if( filter.IsFloatAndNum( str ) )
        {
            cout<<"数字浮点"<<endl;
            continue;
        }
        if( filter.IsAlphabet( str ) )
        {
            cout<<"字母"<<endl;
            continue;
        }
        if( filter.IsFloat( str ))
        {
            cout<<"浮点"<<endl;
            continue;
        }        
        if( filter.IsNum(str) )
        {
            cout<<"数字"<<endl;
            continue;
        }
        if( str == "quit")
        {
            return 0;
        }
    }
       return 0;
}


文件:validfilter.rar
大小:0KB
下载:下载
<script type=text/javascript charset=utf-8 src="http://static.bshare.cn/b/buttonLite.js#style=-1&uuid=&pophcol=3&lang=zh"></script> <script type=text/javascript charset=utf-8 src="http://static.bshare.cn/b/bshareC0.js"></script>
阅读(370) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
评论热议
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
回答: 这个错误信息表明在编译Caffe时,链接器无法找到boost正则表达式库的某些引用。具体来说,这些错误是由于缺少对boost::re_detail::get_default_error_string、boost::basic_regex::do_assign和boost::re_detail::cpp_regex_traits_implementation::transform函数的引用导致的。\[1\]\[2\]\[3\]要解决这个问题,你需要确保你的编译环境中包含了boost正则表达式库,并且正确地链接了这些库。你可以检查你的编译命令中是否包含了正确的库路径和库文件名,并确保你的boost版本与你的编译环境兼容。如果你已经安装了boost库,但仍然遇到这个问题,可能是因为你的编译选项中没有包含正确的boost库路径。你可以尝试在编译命令中添加"-L"选项,后跟boost库的路径,以确保链接器可以找到这些库。另外,你还可以检查你的代码中是否正确地包含了boost正则表达式库的头文件,并且使用了正确的命名空间。希望这些信息对你有帮助。 #### 引用[.reference_title] - *1* *2* *3* [caffe 编译时build_release/lib/libcaffe.so: undefined reference to `boost::cpp_regex_traits](https://blog.csdn.net/m0_37844017/article/details/106911662)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值