gpt4 book ai didi

c# - 解析 AT 命令响应的正则表达式

转载 作者:行者123 更新时间:2023-11-30 16:07:01 25 4
gpt4 key购买 nike

我正在尝试从 AT 命令响应中获取返回消息。

这是输入:

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"

我的预期结果是:

00302220100 Your main balance is 10K, valid until 23/10/2015. For more balance details, please send BAL to 1

这是我的代码:

    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;
}

正则表达式不匹配。请帮助我。非常感谢。

最佳答案

(?<=AT\+[\s\S]*?CUSD:[^"]*")[^"]*

您可以使用变量lookbehindSee 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
}
}

关于c# - 解析 AT 命令响应的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31290443/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com