VC中使用正则表达式
到那个网址下载h和cpp文件,包含进工程
http://research.microsoft.com/projects/greta/
#include <iostream>
#include <string>
#include "regexpr2.h"
using namespace std;
using namespace regex;
#pragma warning(disable:4786)
int main() {
match_results results;
string str( "The book cost $12.34" );
rpattern pat( " ////$(////d+)(////.(////d////d ))?" );
/*
string str( "Javascript" );
rpattern pat( "java(?!script)" ); //rpattern pat( "java(?!script)" ,NOCASE);是不区分大小写
*/
match_results::backref_type br = pat.match( str, results );
if( br.matched ) {
cout << "match success!" << endl;
cout << "price:" << br << endl;
} else {
cout << "match failed!" << endl;
}
return 0;
}
到那个网址下载h和cpp文件,包含进工程
http://research.microsoft.com/projects/greta/
#include <iostream>
#include <string>
#include "regexpr2.h"
using namespace std;
using namespace regex;
#pragma warning(disable:4786)
int main() {
match_results results;
string str( "The book cost $12.34" );
rpattern pat( " ////$(////d+)(////.(////d////d ))?" );
/*
string str( "Javascript" );
rpattern pat( "java(?!script)" ); //rpattern pat( "java(?!script)" ,NOCASE);是不区分大小写
*/
match_results::backref_type br = pat.match( str, results );
if( br.matched ) {
cout << "match success!" << endl;
cout << "price:" << br << endl;
} else {
cout << "match failed!" << endl;
}
return 0;
}
本文介绍如何在Visual C++环境中使用正则表达式进行字符串匹配。通过具体实例演示了正则表达式的使用方法,包括如何下载并引入必要的h和cpp文件,以及如何定义正则表达式模式进行匹配。
240

被折叠的 条评论
为什么被折叠?



