c# - Regular expression to parse AT command response -
i trying return message @ command response.
this input:
at+cusd=1,"*124#",15
ok
+cusd: 2,"00302220100 main balance 10k, valid until 23/10/2015. more balance details, please send bal 1"
my expected result is:
00302220100 main balance 10k, valid until 23/10/2015. more balance details, please send bal 1
here code:
private string parsemessages_chkcredit(string input) { string messages = ""; regex r = new regex("\\at+cusd: (\\d+),\"(.*?)\"", regexoptions.singleline); match m = r.match(input); while (m.success) { messages = m.groups[2].value.tostring(); break; } return messages; } the regular expression not match. please kindly me. lot.
(?<=at\+[\s\s]*?cusd:[^"]*")[^"]* you can make use variable lookbehind.see demo.
string strregex = @"(?<=at\+[\s\s]*?cusd:[^""]*"")[^""]*"; regex myregex = new regex(strregex, regexoptions.none); string strtargetstring = @"at+cusd=1,""*124#"",15" + "\n" + @"ok" + "\n\n" + @"+cusd: 2,""00302220100 main balance 10k, valid until 23/10/2015. more balance details, please send bal 1""" + "\n"; foreach (match mymatch in myregex.matches(strtargetstring)) { if (mymatch.success) { // add code here } }
Comments
Post a Comment