mardi 17 septembre 2019

Regular Expressaions are not match in c++?

I have a problem in regular expression. i have a string and the string is validate with a regular expression and it is working with the python script but not in working in c++ , i will provide my code....... please help me

import re
txt = "\x01msvc-server\x1Cmsvc-xyzy4\x02<?xml version=\"1.0\" encoding=\"UTF-8\"?><SVCMessage currency=\"INR\" hostName=\"msvc-xyz4\" language=\"US-en\" retransmit=\"N\" sequence=\"00\" timeout=\"90\" version=\"8\"><Amount>0.01</Amount><BusinessDate>20190506</BusinessDate><CheckNumber>0</CheckNumber><LocalDate>20170506</LocalDate><LocalTime>160722</LocalTime><RequestCode>POINT_REDEMPTION</RequestCode><RevenueCenter>0</RevenueCenter><TerminalID>21</TerminalID><TraceID>190506860722N000000</TraceID><Track2>1161111112</Track2><TransactionEmployee>0</TransactionEmployee></SVCMessage>\x03\x04"
matcher = re.compile(r".*\x01([A-Za-z0-9_-]*)\x1C([A-Za-z0-9_-]*)\x02([^\x00-\x1F\x7F]*)\x03\x04.*")
results = matcher.match(txt)

if results == None:
    print ('Invalid query , closed')
else:
    print ('sucess')

and my c++ code is that

#include <iostream>
#include <regex>
using namespace std;

int main()
{
    string a = "\x01msvc-server\x1Cmsvc-xyzy4\x02<?xml version=\"1.0\" encoding=\"UTF-8\"?><SVCMessage currency=\"INR\" hostName=\"msvc-xyz4\" language=\"US-en\" retransmit=\"N\" sequence=\"00\" timeout=\"90\" version=\"8\"><Amount>0.01</Amount><BusinessDate>20190506</BusinessDate><CheckNumber>0</CheckNumber><LocalDate>20170506</LocalDate><LocalTime>160722</LocalTime><RequestCode>POINT_REDEMPTION</RequestCode><RevenueCenter>0</RevenueCenter><TerminalID>21</TerminalID><TraceID>190506860722N000000</TraceID><Track2>1161111112</Track2><TransactionEmployee>0</TransactionEmployee></SVCMessage>\x03\x04";
    // Here b is object of regex- Regular Expression
    regex b(".*\x01([A-Za-z0-9_-]*)\x1C([A-Za-z0-9_-]*)\x02([^\x00-\x1F\x7F]*)\x03\x04.*");
    cout<< a << endl;


    if( regex_match(a, b)){
        cout << "String is matches Reguler Expreation " << endl;

    }else{
        cout << "String are not match" << endl;
    }

    return 0;
}


And the expected the result is - String is match........ in c++

Aucun commentaire:

Enregistrer un commentaire