.NET中,使用正则表达式匹配获取所需数据

需求:获取一串字符串中,正则匹配出需要的数据。

例如以下字符串:

string temp ="ErrorCode:-1,Message:{"UserId" : "1000","userName" : "ZhangSan"}";

我需要获得“-1”和“{"UserId" : "1000","userName" : "ZhangSan"}”;

接下来,就使用正则去匹配:

using System.Text.RegularExpressions;

string temp = "ErrorCode:-1,Message:{\"UserId\" : \"1000\",\"userName\" : \"ZhangSan\"}";
Regex reg = new Regex("ErrorCode:(?<key1>.*?),Message:{(?<key2>.*?)}");
Match match = reg.Match(temp);
string tempStr = match.Groups["key1"].Value + "--" + match.Groups["key2"].Value; MessageBox.Show(tempStr);

这时候tempStr得到的是”-1--{"UserId" : "1000","userName" : "ZhangSan"}“

最新文章

  1. 【HDU 2874】Connections between cities(LCA)
  2. delphi XE Berlin ReadProcessMemory WriteProcessMemory
  3. 【228】◀▶ Excel 函数说明
  4. Js数组里删除指定的元素(不是指定的位置)
  5. 带你揭开ATM的神秘面纱
  6. IOS 中的MVC设计模式
  7. Oracle本地,远程,分布式登录
  8. 使用rowid和rownum获取记录时要注意的问题
  9. ASP.NET身份验证的几种方式
  10. 玩转python之字符串逐个字符或逐词反转
  11. Python网络数据采集7-单元测试与Selenium自动化测试
  12. HDU - 1827 Summer Holiday (强连通)
  13. 【Spark篇】---Spark中transformations算子二
  14. js 中常用的循环
  15. ab与nc命令,tcpdump命令
  16. centos 7安装java开发环境
  17. http协议tcp协议ip协议三次握手四次挥手,为什么三次握手,为什么四次挥手,sockete套接字理解
  18. Sonya and Exhibition 1004B
  19. java字符串的遍历以及字符串中各类字符的统计
  20. Struts hibernate Spring 框架原理

热门文章

  1. 二叉苹果树|codevs5565|luoguP2015|树形DP|Elena
  2. 使用FFmpeg常见问题
  3. Installing Precise (12.04.2) using netboot onto a Marvell ArmadaXP Development Board
  4. wpf(windos窗体)
  5. Xcode编译警告Assigning to &#39;id&lt;XXXDelegat&gt; ——Nullable&#39; from incompatible type &#39;XXXView *const_strong&#39;
  6. [others] 一个酷酷的站
  7. day3_元组
  8. LeetCode 104 Maximum Depth of Binary Tree 解题报告
  9. XSL常用用法语句
  10. DER、CRT、CER、PEM格式的证书及转换