我正在使用 gsm 调制解调器,我想解析命令响应。我想用正则表达式来实现它。所以我在下面有文字:
1.AT+CMGF=0
2.
3.OK
4.AT+CMGF=1
5.
6.OK
7.AT+ji
8.
9.ERROR
10.AT+CPMS="ME","ME","ME"
11.
12.+CPMS: 50,100,50,100,50,100
13.
14.OK
15.AT+CMGL="ALL"
16.
17.+CMGL: 0,"REC READ","+7914xxxxxxx",,"12/11/27,12:27:00+44"
18.04DEC0777E03001281 1892
19.+CMGL: 1,"REC READ","+7924xxxxxxx",,"12/11/27,12:33:51+44"
20.04DEC0742E00200176 646411 17983
21.+CMGL: 6,"REC READ","+7924xxxxxxx",,"12/11/27,13:28:00+44"
22.ERROR
23.+CMGL: 7,"REC READ","+79098088xxx",,"12/11/27,12:40:16+44"
24.OK
25.
26.+CMGL: 49,"REC READ","+7924xxxxxxx",,"12/11/27,14:01:01+44"
27.010104480150014300 127051 0020640
28.
29.OK
我需要在每次操作之后捕获ERROR
并OK
从消息中排除它们,以防有人发送它们。我尝试了下一个:
(\r\n)(OK|ERROR)|^("\r\n(OK|ERROR))
但它不起作用。换句话说,我需要排除第 22 行、第 24 行并得到其余的OK
行ERROR
。请帮忙。