- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to find a matching substring using regular expression in C#?
Our string is −
string str = " My make ";
Use the following regular expression to find the substring “make”
@"\bmake\b"
Here is the complete code −
Example
using System; using System.Text.RegularExpressions; namespace RegExApplication { public class Program { private static void showMatch(string text, string expr) { Console.WriteLine("The Expression: " + expr); MatchCollection mc = Regex.Matches(text, expr); foreach(Match m in mc) { Console.WriteLine("Found:" + m); } } public static void Main(string[] args) { string str = "My make"; Console.WriteLine("Matching words start with 'm' and ends with 'e':"); showMatch(str, @"\bmake\b"); } } }
Output
Matching words start with 'm' and ends with 'e': The Expression: \bmake\b Found:make
- Related Articles
- Regular Expression Matching in Python
- Regular Expression Matching in JavaScript
- Lua pattern matching vs regular expression
- How to validate a URL using regular expression in C#?
- How to match a word in python using Regular Expression?
- How to match a whitespace in python using Regular Expression?
- How to Split String in Java using Regular Expression?
- How to match a nonwhitespace character in python using Regular Expression?
- How to match a single character in python using Regular Expression?
- How to find all adverbs and their positions in a text using python regular expression?
- Program to check regular expression pattern is matching with string or not in Python
- How to match only digits in Python using Regular Expression?
- Find all the numbers in a string using regular expression in Python
- How to match digits using Java Regular Expression (RegEx)
- How can I find all matches to a regular expression in Python?

Advertisements