常用的正则表达式
2016-06-27 08:56
309 查看
话不多说,直接上代码
头文件:
源文件:
头文件:
#ifndef __Tools_h__ #define __Tools_h__ #include <string> class Tools { public: static bool verifyEmailAddress(const std::string& email); static bool verifyChinese(const std::string& word); static bool verifyNumber(const std::string& word); static bool verifyNumberAndEnglish(const std::string& word); }; #endif // __Tools_h__
源文件:
#include "Tools.h" #include <regex> namespace Me { bool Tools::verifyEmailAddress(const std::string& email) { std::regex pattern("([0-9A-Za-z\\-_\\.]+)@([0-9a-z]+\\.[a-z]{2,3}(\\.[a-z]{2})?)"); return std::regex_match(email, pattern); } bool Tools::verifyChinese(const std::string& word) { std::regex pattern("^[\u4e00-\u9fa5]+$"); return std::regex_match(word, pattern); } bool Tools::verifyNumber(const std::string& word) { std::regex pattern("^[0-9]*$"); return std::regex_match(word, pattern); } bool Tools::verifyNumberAndEnglish(const std::string& word) { std::regex pattern("^[A-Za-z0-9]+$"); return std::regex_match(word, pattern); } }
相关文章推荐
- msql 正则表达式
- 正则表达式
- Mootools 1.2教程 正则表达式
- 批处理FINDSTR正则表达式用法实例分析
- vbs正则表达式代码
- C#正则表达式Regex类的常用匹配
- C#中利用正则表达式将人民币金额转换为大写汉字
- C#使用正则表达式实现首字母转大写的方法
- php中看实例学正则表达式
- PHP正则表达式之定界符和原子介绍
- PHP下常用正则表达式整理
- 批处理 正则表达式(findstr) 整理
- 详解C#正则表达式Regex常用匹配
- C#正则表达式的6个简单例子
- 正则表达式(语法篇推荐)
- JavaScript类型系统之正则表达式
- 详解JS正则replace的使用方法
- javascript中的正则表达式使用指南
- C#中的正则表达式介绍