正则表达式:*+?

正则表达式百度百科上讲得很详细:

http://baike.baidu.com/link?url=hKRAJWvsUQSqlF9Rbs-09MzYR4LN_ti8kq9jJPoxUGmmohvmpf3PNsVPGRCFXKO3Lo2xjRrNNCSStUJfSso5h6RKUK1K_Xkj4HiiC1o5tbg_NpuS3lR-9I2TVOqDd933NfhQvO5SF-hxFDqnIkfdgq

下面给出一个例子

在以下文件中找出fsw<<到<<之间所有内容包括<<

fsw<<(int)mnId;
    fsw<<"mTimeStamp"<<mTimeStamp;
    fsw<<"mnGridCols"<<mnGridCols;
    fsw<<"mnGridRows"<<mnGridRows;
    fsw<<"mfGridElementWidthInv"<<mfGridElementWidthInv;
    fsw<<"mfGridElementHeightInv"<<mfGridElementHeightInv;
    fsw<<"mnTrackReferenceForFrame"<<(int)mnTrackReferenceForFrame;
    fsw<<"mnFuseTargetForKF"<<(int)mnFuseTargetForKF;
    fsw<<"mnBALocalForKF"<<(int)mnBALocalForKF;
    fsw<<"mnBAFixedForKF"<<(int)mnBAFixedForKF;
    fsw<<"mnLoopQuery"<<(int)mnLoopQuery;
    fsw<<"mnLoopWords"<<mnLoopWords;
    fsw<<"mLoopScore"<<mLoopScore;
    fsw<<"mnRelocQuery"<<(int)mnRelocQuery;
    fsw<<"mnRelocWords"<<mnRelocWords;
    fsw<<"mRelocScore"<<mRelocScore;
    fsw<<"mTcwGBA"<<mTcwGBA;
    fsw<<"mTcwBefGBA"<<mTcwBefGBA;
    fsw<<"mnBAGlobalForKF"<<(int)mnBAGlobalForKF;
    fsw<<"fx"<<fx;
    fsw<<"fy"<<fy;
    fsw<<"cx"<<cx;
    fsw<<"cy"<<cy;
    fsw<<"invfx"<<invfx;
    fsw<<"invfy"<<invfy;
    fsw<<"mbf"<<mbf;
    fsw<<"mb"<<mb;
    fsw<<"mThDepth"<<mThDepth;

    fsw<<"mvKeys";
    fsw<<"[";
    for(std::vector<cv::KeyPoint>::const_iterator it = mvKeys.begin(); it!=mvKeys.end();it++)
    {
        fsw<<"{";
        fsw<<"angle"<< it->angle;
        fsw<<"octave"<<it->octave;
        fsw<<"x"<<it->pt.x;
        fsw<<"y"<<it->pt.y;
        fsw<<"}";
    }
    fsw<<"]";

    fsw<<"mvKeysUn";
    fsw<<"[";
    for(std::vector<cv::KeyPoint>::const_iterator it = mvKeysUn.begin(); it!=mvKeysUn.end();it++)
    {
        fsw<<"{";
        fsw<<"angle"<< it->angle;
        fsw<<"octave"<<it->octave;
        fsw<<"x"<<it->pt.x;
        fsw<<"y"<<it->pt.y;
        fsw<<"}";
    }
    fsw<<"]";

    fsw<<"mvuRight"<<mvuRight;
    fsw<<"mvDepth"<<mvDepth;
    fsw<<"mDescriptors"<<mDescriptors;


    fsw<<"mTcp"<<mTcp;

    fsw<<"mnScaleLevels"<<mnScaleLevels;
    fsw<<"mfScaleFactor"<<mfScaleFactor;
    fsw<<"mfLogScaleFactor"<<mfLogScaleFactor;
    fsw<<"mvScaleFactors"<<mvScaleFactors;
    fsw<<"mvLevelSigma2"<<mvLevelSigma2;
    fsw<<"mvInvLevelSigma2"<<mvInvLevelSigma2;
    fsw<<"mnMinX"<<mnMinX;
    fsw<<"mnMinY"<<mnMinY;
    fsw<<"mnMaxX"<<mnMaxX;
    fsw<<"mnMaxY"<<mnMaxY;
    fsw<<"mK"<<mK;
    fsw<<"Tcw"<<Tcw;
    fsw<<"Twc"<<Twc;
    fsw<<"Ow"<<Ow;
    fsw<<"Cw"<<Cw;



    fsw<<"mvpMapPoints";
    fsw<<"[";
    for(std::vector<MapPoint*>::const_iterator it = mvpMapPoints.begin();it!=mvpMapPoints.end();it++)
    {
        if(*it)
        fsw<<(int)((*it)->mnId);
    }
    fsw<<"]";


    fsw<<"mGrid";
    std::vector< std::vector <std::vector<int> > > mGrid_int;
    std::vector<std::vector<int>> mGrid_int1;
    std::vector<int> mGrid_int2;
    int num;
    for(std::vector< std::vector <std::vector<size_t> > >::const_iterator it2 = mGrid.begin(); it2!=mGrid.end();it2++)
    {
        for(std::vector <std::vector<size_t> >::const_iterator it1 = it2->begin(); it1!=it2->end();it1++)
        {
            for(std::vector<size_t>::const_iterator it0 = it1->begin();it0!=it1->end();it0++)
            {
                num = *it0;
                mGrid_int2.push_back(*it0);
            }
            mGrid_int1.push_back(mGrid_int2);
            mGrid_int2.clear();
            }
            mGrid_int.push_back(mGrid_int1);
            mGrid_int1.clear();
    }
    fsw<<"[";
    for(unsigned int i = 0 ; i<mGrid_int.size();i++)
    {
        mGrid_int1 = mGrid_int[i];
        fsw<<"[";
        for(unsigned int j =0 ; j<mGrid_int1.size();j++)
        {
            mGrid_int2 = mGrid_int1[j];
            fsw<<mGrid_int2;
        }
        fsw<<"]";
     }
     fsw<<"]";


    fsw<<"mConnectedKeyFrameWeights";
    fsw<<"[";
    for(std::map<KeyFrame*,int>::const_iterator it = mConnectedKeyFrameWeights.begin();it!=mConnectedKeyFrameWeights.end();it++)
    {
       if(it->first)
       {
       fsw<<"{";
       fsw<<"mnId"<<(int)(it->first->mnId);
       fsw<<"weight"<<it->second;
       fsw<<"}";
       }
    }
    fsw<<"]";


    fsw<<"mvpOrderedConnectedKeyFrames";
    fsw<<"[";
    for(std::vector<KeyFrame*>::const_iterator it = mvpOrderedConnectedKeyFrames.begin();it!=mvpOrderedConnectedKeyFrames.end();it++)
    {
       if(*it)
       fsw<<(int)((*it)->mnId);

    }
    fsw<<"]";

    fsw<<"mvOrderedWeights"<<mvOrderedWeights;
    if(mbFirstConnection)
            fsw<<"mbFirstConnection"<<"true";
        else
            fsw<<"mbFirstConnection"<<"false";


    if(mpParent)
    fsw<<"mpParent"<<(int)(mpParent->mnId);

    fsw<<"mspChildrens";
    fsw<<"[";
    for(std::set<KeyFrame*>::const_iterator it=mspChildrens.begin();it!=mspChildrens.end();it++)
    {
        if(*it)
        fsw<<(int)((*it)->mnId);
    }
    fsw<<"]";


    fsw<<"mspLoopEdges";
    fsw<<"[";
    for(std::set<KeyFrame*>::const_iterator it=mspLoopEdges.begin();it!=mspLoopEdges.end();it++)
        if(*it)
            fsw<<(int)((*it)->mnId);
    fsw<<"]";

    if(mbNotErase)
        fsw<<"mbNotErase"<<"true";
    else
        fsw<<"mbNotErase"<<"false";



    if(mbToBeErased)
        fsw<<"mbToBeErased"<<"true";
    else
        fsw<<"mbToBeErased"<<"false";

    if(mbBad)
        fsw<<"mbBad"<<"true";
    else
        fsw<<"mbBad"<<"false";

    fsw<<"mHalfBaseline"<<mHalfBaseline;

可以使用正则表达式<<+"[a-z]*"+<+

下面详细解释

+是匹配前面表达式一次或者多次

*是匹配前面表达式任意多次

于是就能够找到fsw<<"mHalfBaseline"<<类似内容了

用来替换内容很方便,不用一个个敲

posted @ 2017-04-11 15:14  每天一点积累  阅读(2970)  评论(0编辑  收藏  举报