对这个实例有什么问题可以联系我,方式见上。
#include <cstdlib>
#include <stdlib.h>
#include <boost/regex.hpp>
#include <string>
#include <iostream>
using namespace std;
using namespace boost;
//regex expression("(!AIVD[MO],.{0,70},[0-9][*][0-9A-Z][0-9A-Z])");
regex expression("(!AIVD[MO],.{0,70},[0-9][*][0-9A-Z][0-9A-Z])");
string* AIS_Regex_Separate(string Raw,regex regex,string *OutMsg,int FrontOffset,int BackOffset)
{
/*****************************************************
* FrontOffset and BackOffset must be positive Num
*****************************************************/
cmatch what; unsigned int i =0 ;
while(regex_search(Raw.c_str(), what, regex))
{
OutMsg[i].assign(what[0].str());
OutMsg[i].erase(0,FrontOffset);
OutMsg[i].resize(OutMsg[i].length()-BackOffset);
i++;
Raw.erase(0,Raw.find_first_of("*")+1);
}
for(unsigned int j=0;j<i;j++)
{
cout<<OutMsg[j]<<endl;
}
return OutMsg ;
}
int main(int argc, char* argv[])
{
string msg[1000];
string in="!AIVDM,2,1,3,A,577K2:02;M1AI9HkP01DpUHE9<4j0lfo;33P000`40=664000422isC@,0*2F\
!AIVDM,1,1,,B,16:fVHgP0289>ln<okPh0?wH08On,0*71\
2012-06-06 16:57:40-318 : !AIVDM,1,1,,A,169FecPP3N891A0<joQApgwJ0598,0*63 as\
2012-06-06 16:57:40-380 : !AIVDM,1,1,,B,16:9vMgP0088piV<hF2uA?wJ08JO,0*79dasf\
2012-06-06 16:57:40-412 : !AIVDM,1,1,,B,168uU8001L88MA2<teudTJ;J2598,0*14\
2012-06-06 16:57:40-459 : !AIVDO,1,1,,,10`:DoOP00`99RB<pHSb5gwL2000,0*24\
2012-06-06 16:57:40-459 : !AIVDM,1,1,,B,16:D7a003v`8l:P<q251;0mL00S6,0*25fasf\
2012-06-06 16:57:40-490 : !AIVDM,1,1,,A,169hDD004f`79?`=107;9`sJ08JS,0*52 \
2012-06-06 16:57:40-537 : !AIVDM,1,1,,A,403tAEiuiS9Be89E4d<nor1008JU,0*14fdsf\
2012-06-06 16:57:40-630 : !AIVDM,1,1,,A,169oQ?wP05899lv<p>kJAwwJ0@7N,0*48fasdf\
2012-06-06 16:57:40-693 : !AIVDM,1,1,,A,169GIPPP00899;n<oo`<?wwKpHJc,0*2E\
2012-06-06 16:57:40-771 : !AIVDM,1,1,,A,100000?P?w<tSF0l4Q@>4?wJ0`Jf,0*50\
2012-06-06 16:57:40-865 : !AIVDM,1,1,,B,169v:Q?P00`98w4<oqgh0?wJ00RE,0*43\
2012-06-06 16:57:40-865 : !AIVDM,1,1,,A,169dV2005388pfT<r6wdh:EL0HJi,0*37\
2012-06-06 16:57:40-990 : !AIVDM,1,1,,A,16:V4UwP0089>LF<owkP0?wJ0<1i,0*47\
2012-06-06 16:57:41-099 : !AIVDM,1,1,,B,39NWqQEP00878Of==KvJ:wwJ0000,0*1A\
!AIVDM,2,1,3,A,577K2:02;M1AI9HkP01DpUHE9<4j0lfo;33P000`40=664000422isC@,0*2F\
!AIVDM,2,2,3,A,@h0000000000000,2*0F\
!AIVDM,1,1,,B,9002=mQq1oIJvt6;2eUn>Sh0040<,0*5D\
!AIVDM,1,1,,A,>5?Per18=HB1U:1@E=B0m<L,2*51\
!AIVDM,1,1,,B,C5N3SRP0IFJKmE4:v6pBGw`@62PaLELTBJ:V00000000S0D:R220,0*3A\
!AIVDM,2,1,5,B,E1mg=5J1T4W0h97aRh6ba84<h2d;W:Te=eLvH50```q,0*46\
!AIVDM,2,2,5,B,:D44QDlp0C1DU00,2*36\
!AIVDM,1,1,,B,15Mq4J0P01EREODRv4@74gv00HRq,0*88\
!AIVDM,1,1,,A,;4eG>3iuaFP2:r3OiBH7;8i00000,0*65\
!AIVDM,1,1,,A,B5N3SRP0FFJFC`4:CQDFKwiP200>,0*75\
!AIVDM,1,1,,B,H5NHcTP<51@4TrM>10584@U<D000,2*77 ";
;
AIS_Regex_Separate(in,expression,msg,1,5);
return 0;
}