What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 12054 |  Welcome, Guest!   Register  Login
 Home > Code Snippets > C# > Regular Expression to search words with specified number of characters ...
Madhu.b.rokkam

Regular Expression to search words with specified number of characters

 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:


>> Write Response - Respond to this post and get points

More codes snippets

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/22/2013 5:55:52 AM