C#-正则表达式的使用---ShinePans
来源:互联网 发布:ug车床编程视频 编辑:程序博客网 时间:2024/05/21 19:33
//正则表达式分解字符串//Regex:表示不可变的正则表达式//Matches:在输入字符串中搜索正则表达式的所有匹配项并返回所有成功的匹配,类比为多次调用match方法//Groups:获取由正则表达式匹配的集合using System;using System.Text;using System.IO;using System.Security.Cryptography;using System.Text.RegularExpressions; //正则表达式class program{ static string encryptKey = "Fuck"; //加密密匙 static void Main(string[] args) { string str = "16:08:30 192.168.1.1 你好 16:09:00 192.168.0.1 大家好"; Regex myRegex = new Regex(@"(?<time>(\d|\:)+)\s" + @"(?<ip>(\d|\.)+)\s" + @"(?<company>\S+)\s"); //对字符串按指定格式进行分解 MatchCollection myMatches = myRegex.Matches(str); string strNew=""; foreach(Match myMatch in myMatches) { strNew+="\n 时间:"+myMatch.Groups["time"].ToString(); strNew+="\n 地址:"+myMatch.Groups["ip"].ToString(); strNew+="\n 再说一句:"+myMatch.Groups["company"].ToString()+"\n"; } Console.WriteLine(strNew); Console.ReadLine(); }}
8 0
- C#-正则表达式的使用---ShinePans
- C#-StringBuilder类的使用---ShinePans
- 正则表达式的使用(C++)
- C#-控制台-Char类的使用大全---ShinePans
- C#——正则表达式的使用
- C语言正则表达式的使用
- Objective-C 正则表达式的使用
- 【C#】C#中正则表达式的使用
- C的正则表达式
- C#利用正则表达式实现字符串搜索---ShinePans
- 【C/C++】boost regex正则表达式的安装及使用
- C++/C中使用轻量级的正则表达式
- 使用GNU C正则表达式
- [object-c]使用正则表达式
- Linux c 使用正则表达式
- C语言使用正则表达式
- C中使用正则表达式
- linux c 使用正则表达式
- 第六周作业 图片缩放显示
- VS2010 LNK1123: 转换到 COFF 期间失败: 文件无效或损坏 的解决方法
- Java连接本地MySQL数据库进行增删改查操作
- JAVAFX的TableView的单元格可编辑
- [leetcode]Climbing Stairs
- C#-正则表达式的使用---ShinePans
- ExpandableListView用法的一个简单小例子
- 教你以gcc的方式使用Visual Studio 2013 tool
- Android 中 CursorAdapter 的用法
- 修正 Android cocos2d-x FATAL EXCEPTION: GLThread 105的错误
- Linux文件权限(一)
- php 实现简单链式二叉树 创建 和遍历
- python 批量修改图片的文件名
- 数据结构9:斐波那契数列表示与实现(递归)