COM PORT中消息发送确认的Regualar表达式 [英] Regualar Expression for Message Sent Confirmation in COM PORT

查看:122
本文介绍了COM PORT中消息发送确认的Regualar表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用gsm调制解调器在c#中开发应用程序



当我使用AT命令发送消息时,它返回确认消息



REL LOCK OPEN \\\\ n + CMGS:67 \\\\\\\\\\\ n



所以我如何才能将上述内容与正则表达式相匹配



i我正在尝试这个



正则表达式r =新的正则表达式(@\\ n(。+)\\\\\ + CMGS :( \d +)\\\\\\\ n 。+)\ r \ n;



但它不起作用

i am developing a application in c# using gsm modem

when i send a message using AT command, it returns a confirmation messsage

"REL LOCK OPEN\r\n+CMGS: 67\r\n\r\nOK\r\n"

so how can i match the above with regular expression

i am trying this

Regex r = new Regex(@"\r\n(.+)\r\n\+CMGS: (\d+)\r\n\r\n(.+)\r\n");

but it's not working

推荐答案

首先,忽略换行 - 或者更好,使用string.replace处理它们,然后处理它('\ n'不一定是你的想法,并且正则表达式不适合它们):

Firstly, ignore the newlines - or better, dispose of them using string.replace, then work on that ('\n' is not necessarily what you think, and Regexes don't work well with them):
string inp = @"REL LOCK OPEN\r\n+CMGS: 67\r\n\r\nOK\r\n";
inp = inp.Replace(@"\r\n", @"


);
匹配m = Regex.Match(inp, @ (。+)\
"); Match m = Regex.Match(inp, @"(.+)\


\ + CMGS:(\d +)\
\+CMGS: (\d+)\


这篇关于COM PORT中消息发送确认的Regualar表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆