I am trying to get a return message from AT command response.
This is the input:
AT+CUSD=1,"*124#",15
OK
+CUSD: 2,"00302220100 Your main balance is 10K, valid until 23/10/2015. For more balance details, please send BAL to 1"
My expected result is:
00302220100 Your main balance is 10K, valid until 23/10/2015. For more balance details, please send BAL to 1
Here is my 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 does not match. Please kindly help me. Thanks a 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 Your main balance is 10K, valid until 23/10/2015. For more balance details, please send BAL to 1""" + "\n";
foreach (Match myMatch in myRegex.Matches(strTargetString))
{
if (myMatch.Success)
{
// Add your code here
}
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments