Code Snippet posted by:
Madhu.b.rokkam | Posted on: 2/27/2011 | Category:
C# Codes | Views: 1359 | Status:
[Member] [MVP] |
Points: 40
|
Alert Moderator
//Search words with 5 or more characters
Regex regex = new Regex("[a-zA-Z]{5,}");
Example
string sourceString = "We are Indians, we are Engineers, we are part of DNF ...";
//Regex regex = new Regex("are");
Regex regex = new Regex("[a-zA-Z]{5,}");
MatchCollection matchCol = regex.Matches(sourceString);
foreach (Match match in matchCol)
{
Console.WriteLine(string.Format("{0} is at {1} position of the string", match.Value.Trim(), match.Index));
}
output
Indians is at 7 position of the string
Engineers is at 23 position of the string
Thanks and Regards
Madhu
Found interesting? Add this to: