match.cpp

来自「linux下实现对mysql数据库的连接及相关的插入、删除和查找工作。」· C++ 代码 · 共 36 行

CPP
36
字号
# include<iostream>
# include<fstream>
# include <cstdio>
# include<string>
# include<regex.h>
# define nmatch 5
using namespace std;

string GetMatchContent(string strContent,string matchContent)
{
		regex_t preg;
		string content;
		char regex[]="[0-9]+\\.[0-9]+";
		regmatch_t pmatch[nmatch];
		int position=strContent.find(matchContent);
		if(position<0)
				return "";
		string tempStr=strContent.substr(position,50);
		if(regcomp(&preg,regex,REG_EXTENDED)==0)
		{
				if(regexec(&preg,tempStr.c_str(),nmatch,pmatch,0)==0)
				{
						for(int i=0;i<5;i++)
						{
								if(pmatch[i].rm_so==-1)
										continue;
								content=tempStr.substr(pmatch[i].rm_so,pmatch[i].rm_eo-pmatch[i].rm_so);
				   
						}
				}
		}
        regfree(&preg);
		return content;

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?