Regex 小试
来源:互联网 发布:戈洛夫金力量数据 编辑:程序博客网 时间:2024/06/13 06:59
对于正则表达式的几具尝试
static void Main(string[] args) { string input = "This is,text with,far%too much whitespace."; string pattern = ","; string replacement = "&"; Regex rgx = new Regex(pattern); string result = rgx.Replace(input, replacement); Console.WriteLine("Original String: {0}", input); Console.WriteLine("Replacement String: {0}", result); Console.Read(); }
输出结果:Original String : This is,text with,far%too much whitespace.
Replacement String: This is&text with&far%too much whitespace.
2).
string pattern = ",|%";输出结果:
Original String : This is,text with,far%too much whitespace.
Replacement String: This is&text with&far&too much whitespace.
3).
string pattern = "[,%]";
输出结果:
Original String : This is,text with,far%too much whitespace.
Replacement String: This is&text with&far&too much whitespace.
4).
string pattern = ",%";
Original String : This is,text with,far%too much whitespace.
Replacement String: This is,text with,far%too much whitespace.
5)
string input = "This is,text with,far%too much,% whitespace.";string pattern = "(,%)";
输出结果:
Original String : This is,text with,far%too much,% whitespace.
Replacement String: This is,text with,far%too much& whitespace.
总结下:
[ ]:选择, ():整体, |:或
- Regex 小试
- Regex的小用法
- C++04:使用Boost-小试Regex库
- Boost-小试Regex库 代码实现的功能:找出html文件中的所有链接
- Regex
- Regex
- Regex
- Regex
- regex
- Regex
- regex
- Regex
- regex
- Regex
- regex
- Regex
- regex
- Regex
- 排序算法实现及分析
- release版本崩溃,如何定位代码行
- 字符串转换为整数
- Visual Studio打包(Windows Installer),你不知道的RemovePreviousVersions 属性
- VS2010 对话框添加菜单
- Regex 小试
- WinDbg !locks 不可用的问题
- java 线程的暂停与开始
- UITextView使用技巧(一)
- 在同一个tomcat下,不同的web项目共享session
- ip_route_output_slow注释
- php var_dump和var_export
- Hadoop 项目简单介绍
- MySQL忘记密码恢复密码的实现方法