c#中的正则表达式 [英] regular expression in c#
本文介绍了c#中的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
文字可以是:
连续12个月(续订期限)给予
或句子可以是
连续第二个月(续订期限)给予
输出应该是 12个连续月份或连续两个月{s
使用正则表达式模式。
模式将是一个可以获取所需输出的模式..
亲切帮助
The text can be :
additional 12 consecutive month{s)("Renewal Term") by giving
or sentence can be
additional twelth consecutive month{s)("Renewal Term") by giving
output should be "12 consucutive month(s)" or "twelth consecutive month{s)"
using regex pattern .
pattern would be one which fetch me the desired output..
kindly help
推荐答案
将12,twelth或第12替换为:12:
This replaces "12," "twelth," or "twelfth," with: "twelve:"
// required
using System.Text.RegularExpressions;
//somewhere in a method
string s = @"additional twelfth consecutive month(s) (""Renewal Term"") by giving";
Regex r = new Regex(@"\b12\b|\btwelth\b|\btwelfth\b");
s = r.Replace(s, "twelve");
试试这个免费的魔法正则表达式生成器
http://txt2re.com/index-csharp.php3 [ ^ ]
只需提供完整的句子,然后指出所需的模式,它将以您选择的语言生成代码。
Try this free magic regex generator at
http://txt2re.com/index-csharp.php3[^]
Just supply the full sentence, then indicate the desired pattern, it will generate code in the language of your choice.
虽然这不会为您编写代码,但它可以帮助您学习RegEx。一个非常有用的网站是 regexlib [ ^ ];他们有一个庞大的正则表达式库。他们还有一个 RegEx测试人员 [ ^ ]。此外,还有一个非常有用的RegEx工具此处 [ ^ ]。
Although this does not write your code for you it will help you to learn RegEx. A very helpful site is regexlib[^]; they have a large library of Regular Expressions. They also have a RegEx tester[^]. Also a very useful RegEx tool is available here[^].
这篇关于c#中的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文