简体   繁体   English

从模式中提取文本

[英]Extract text from pattern

i have a sim 800 module.我有一个 sim 800 模块。 i read all message that stored in sim card.我阅读了存储在 SIM 卡中的所有消息。 that return bellow response.返回下面的响应。 i want separate phone number,time and text from response.我想要单独的电话号码、时间和回复文本。 but i don't know how但我不知道怎么做


+CMGL: 1,"REC READ","number","","2019/10/11 17:09:44+14"
this is text

+CMGL: 2,"REC READ","989149161278","","2019/10/11 17:38:18+14"
this is text

+CMGL: 3,"REC READ","989149161278","","2019/10/11 17:55:03+14"
this is text

+CMGL: 4,"REC READ","989149161278","","2019/10/11 17:57:09+14"
this is text

+CMGL: 5,"REC READ","989149161278","","2019/10/11 18:14:22+14"
this is text

+CMGL: 13,"REC READ","989149161278","","2019/10/11 19:04:40+14"
this is text

+CMGL: 14,"REC READ","989149161278","","2019/10/11 19:07:12+14"
this is text

+CMGL: 15,"REC READ","989149161278","","2019/10/11 19:08:23+14"
this is text

+CMGL: 16,"REC READ","989149161278","","2019/10/11 19:21:17+14"
this is text

+CMGL: 17,"REC READ","989149161278","","2019/10/11 19:30:31+14"
this is text

+CMGL: 18,"REC READ","989149161278","","2019/10/11 20:15:49+14"
this is text

+CMGL: 19,"REC READ","989149161278","","2019/10/11 20:41:36+14"
this is text

+CMGL: 20,"REC READ","number","","2019/10/11 20:41:41+14"
this is text

OK

This may be not the best way, but considering your response structure will always stay the same, consider:这可能不是最好的方法,但考虑到您的响应结构将始终保持不变,请考虑:

\+CMGL:\s\d+\,\"REC\sREAD\",\"(?<phone>.+)\",\"(?:.+)?\",\"(?<time>.+)\"|^(?<message>.+)$

Regex Demo正则表达式演示

Essentially, capturing the entire string and extracting necessary information via groups.本质上,捕获整个字符串并通过组提取必要的信息。 You can access individual groups via group names (see link right side).您可以通过组名访问各个组(参见右侧的链接)。

You should look into this to fix your problem.您应该对此进行调查以解决您的问题。 https://www.tutorialspoint.com/csharp/csharp_regular_expressions.htm https://www.tutorialspoint.com/csharp/csharp_regular_expressions.htm

Alternatively you can also use the string split method to divide up the content between your commas.或者,您也可以使用字符串拆分方法来划分逗号之间的内容。 https://www.geeksforgeeks.org/string-split-method-in-c-sharp-with-examples/ https://www.geeksforgeeks.org/string-split-method-in-c-sharp-with-examples/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM