Click here to Skip to main content
15,899,124 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Comments
BillWoodruff 11-Dec-13 10:45am    
fyi: in your input examples you are using "s" bracketed between an open curly-brace and a close-parens.

"twelth" is a very common misspelling of "twelfth," but, in this case, "twelfth" would not be grammatically correct: the correct term is "twelve."

Your example of desired output spells "consecutive" as "consucative."

once a proofreader, always a proofreader :)

This replaces "12," "twelth," or "twelfth," with: "twelve:"
C#
// 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");
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 11-Dec-13 12:58pm    
Not really useful I guess, but a 5, because inquirers get what they ask for. :-)
—SA
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.
 
Share this answer
 
v2
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[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900