
Domains
Agile Management
Master Agile methodologies for efficient and timely project delivery.
View All Agile Management Coursesicon-refresh-cwCertifications
Scrum Alliance
16 Hours
Best Seller
Certified ScrumMaster (CSM) CertificationScrum Alliance
16 Hours
Best Seller
Certified Scrum Product Owner (CSPO) CertificationScaled Agile
16 Hours
Trending
Leading SAFe 6.0 CertificationScrum.org
16 Hours
Professional Scrum Master (PSM) CertificationScaled Agile
16 Hours
SAFe 6.0 Scrum Master (SSM) CertificationAdvanced Certifications
Scaled Agile, Inc.
32 Hours
Recommended
Implementing SAFe 6.0 (SPC) CertificationScaled Agile, Inc.
24 Hours
SAFe 6.0 Release Train Engineer (RTE) CertificationScaled Agile, Inc.
16 Hours
Trending
SAFe® 6.0 Product Owner/Product Manager (POPM)IC Agile
24 Hours
ICP Agile Certified Coaching (ICP-ACC)Scrum.org
16 Hours
Professional Scrum Product Owner I (PSPO I) TrainingMasters
32 Hours
Trending
Agile Management Master's Program32 Hours
Agile Excellence Master's ProgramOn-Demand Courses
Agile and ScrumRoles
Scrum MasterTech Courses and Bootcamps
Full Stack Developer BootcampAccreditation Bodies
Scrum AllianceTop Resources
Scrum TutorialProject Management
Gain expert skills to lead projects to success and timely completion.
View All Project Management Coursesicon-standCertifications
PMI
36 Hours
Best Seller
Project Management Professional (PMP) CertificationAxelos
32 Hours
PRINCE2 Foundation & Practitioner CertificationAxelos
16 Hours
PRINCE2 Foundation CertificationAxelos
16 Hours
PRINCE2 Practitioner CertificationSkills
Change ManagementMasters
Job Oriented
45 Hours
Trending
Project Management Master's ProgramUniversity Programs
45 Hours
Trending
Project Management Master's ProgramOn-Demand Courses
PRINCE2 Practitioner CourseRoles
Project ManagerAccreditation Bodies
PMITop Resources
Theories of MotivationCloud Computing
Learn to harness the cloud to deliver computing resources efficiently.
View All Cloud Computing Coursesicon-cloud-snowingCertifications
AWS
32 Hours
Best Seller
AWS Certified Solutions Architect - AssociateAWS
32 Hours
AWS Cloud Practitioner CertificationAWS
24 Hours
AWS DevOps CertificationMicrosoft
16 Hours
Azure Fundamentals CertificationMicrosoft
24 Hours
Best Seller
Azure Administrator CertificationMicrosoft
45 Hours
Recommended
Azure Data Engineer CertificationMicrosoft
32 Hours
Azure Solution Architect CertificationMicrosoft
40 Hours
Azure DevOps CertificationAWS
24 Hours
Systems Operations on AWS Certification TrainingAWS
24 Hours
Developing on AWSMasters
Job Oriented
48 Hours
New
AWS Cloud Architect Masters ProgramBootcamps
Career Kickstarter
100 Hours
Trending
Cloud Engineer BootcampRoles
Cloud EngineerOn-Demand Courses
AWS Certified Developer Associate - Complete GuideAuthorized Partners of
AWSTop Resources
Scrum TutorialIT Service Management
Understand how to plan, design, and optimize IT services efficiently.
View All DevOps Coursesicon-git-commitCertifications
Axelos
16 Hours
Best Seller
ITIL 4 Foundation CertificationAxelos
16 Hours
ITIL Practitioner CertificationPeopleCert
16 Hours
ISO 14001 Foundation CertificationPeopleCert
16 Hours
ISO 20000 CertificationPeopleCert
24 Hours
ISO 27000 Foundation CertificationAxelos
24 Hours
ITIL 4 Specialist: Create, Deliver and Support TrainingAxelos
24 Hours
ITIL 4 Specialist: Drive Stakeholder Value TrainingAxelos
16 Hours
ITIL 4 Strategist Direct, Plan and Improve TrainingOn-Demand Courses
ITIL 4 Specialist: Create, Deliver and Support ExamTop Resources
ITIL Practice TestData Science
Unlock valuable insights from data with advanced analytics.
View All Data Science Coursesicon-dataBootcamps
Job Oriented
6 Months
Trending
Data Science BootcampJob Oriented
289 Hours
Data Engineer BootcampJob Oriented
6 Months
Data Analyst BootcampJob Oriented
288 Hours
New
AI Engineer BootcampSkills
Data Science with PythonRoles
Data ScientistOn-Demand Courses
Data Analysis Using ExcelTop Resources
Machine Learning TutorialDevOps
Automate and streamline the delivery of products and services.
View All DevOps Coursesicon-terminal-squareCertifications
DevOps Institute
16 Hours
Best Seller
DevOps Foundation CertificationCNCF
32 Hours
New
Certified Kubernetes AdministratorDevops Institute
16 Hours
Devops LeaderSkills
KubernetesRoles
DevOps EngineerOn-Demand Courses
CI/CD with Jenkins XGlobal Accreditations
DevOps InstituteTop Resources
Top DevOps ProjectsBI And Visualization
Understand how to transform data into actionable, measurable insights.
View All BI And Visualization Coursesicon-microscopeBI and Visualization Tools
Certification
24 Hours
Recommended
Tableau CertificationCertification
24 Hours
Data Visualization with Tableau CertificationMicrosoft
24 Hours
Best Seller
Microsoft Power BI CertificationTIBCO
36 Hours
TIBCO Spotfire TrainingCertification
30 Hours
Data Visualization with QlikView CertificationCertification
16 Hours
Sisense BI CertificationOn-Demand Courses
Data Visualization Using Tableau TrainingTop Resources
Python Data Viz LibsCyber Security
Understand how to protect data and systems from threats or disasters.
View All Cyber Security Coursesicon-refresh-cwCertifications
CompTIA
40 Hours
Best Seller
CompTIA Security+EC-Council
40 Hours
Certified Ethical Hacker (CEH v12) CertificationISACA
22 Hours
Certified Information Systems Auditor (CISA) CertificationISACA
40 Hours
Certified Information Security Manager (CISM) Certification(ISC)²
40 Hours
Certified Information Systems Security Professional (CISSP)(ISC)²
40 Hours
Certified Cloud Security Professional (CCSP) Certification16 Hours
Certified Information Privacy Professional - Europe (CIPP-E) CertificationISACA
16 Hours
COBIT5 Foundation16 Hours
Payment Card Industry Security Standards (PCI-DSS) CertificationOn-Demand Courses
CISSPTop Resources
Laptops for IT SecurityWeb Development
Learn to create user-friendly, fast, and dynamic web applications.
View All Web Development Coursesicon-codeBootcamps
Career Kickstarter
6 Months
Best Seller
Full-Stack Developer BootcampJob Oriented
3 Months
Best Seller
UI/UX Design BootcampEnterprise Recommended
6 Months
Java Full Stack Developer BootcampCareer Kickstarter
490+ Hours
Front-End Development BootcampCareer Accelerator
4 Months
Backend Development Bootcamp (Node JS)Skills
ReactOn-Demand Courses
Angular TrainingTop Resources
Top HTML ProjectsBlockchain
Understand how transactions and databases work in blockchain technology.
View All Blockchain Coursesicon-stop-squareBlockchain Certifications
40 Hours
Blockchain Professional Certification32 Hours
Blockchain Solutions Architect Certification32 Hours
Blockchain Security Engineer Certification24 Hours
Blockchain Quality Engineer Certification5+ Hours
Blockchain 101 CertificationOn-Demand Courses
NFT Essentials 101: A Beginner's GuideTop Resources
Blockchain Interview QsProgramming
Learn to code efficiently and design software that solves problems.
View All Programming Coursesicon-codeSkills
Python CertificationInterview Prep
Career Accelerator
3 Months
Software Engineer Interview PrepOn-Demand Courses
Data Structures and Algorithms with JavaScriptTop Resources
Python TutorialRegular expressions denote different patterns like literals, constructs, operators etc. that can be matched with the input.
The immutable regular expressions are represented using a Regex Class. Details about the Regex class is given as follows:
The different constructors and their description is given as follows:
Constructors | Description |
|---|---|
Regex() | This constructor initializes a new instance of the Regex class. |
Regex(SerializationInfo, StreamingContext) | This constructor initializes a new instance of the Regex class by using serialized data. |
Regex(String) | This constructor initializes a new instance of the Regex class for the specified regular expression |
Regex(String, RegexOptions) | This constructor initializes a new instance of the Regex class for the specified regular expression, with options that modify the pattern. |
Regex(String, RegexOptions, TimeSpan) | This constructor initializes a new instance of the Regex class for the specified regular expression, with options that modify the pattern and a value that specifies how long a pattern matching method should attempt a match before it times out. |
Table: Constructors in Regex Class in C#
Source: MSDN
The different fields and their description is given as follows:
Fields | Description |
|---|---|
capnames | This field is used by a Regex object generated by the CompileToAssembly method. |
caps | This field is used by a Regex object generated by the CompileToAssembly method. |
capsize | This field is used by a Regex object generated by the CompileToAssembly method. |
capslist | This field is used by a Regex object generated by the CompileToAssembly method. |
factory | This field is used by a Regex object generated by the CompileToAssembly method. |
InfiniteMatchTimeout | This timeout is used by a Regex object generated by the CompileToAssembly method. |
internalMatchTimeout | This timeout is the maximum amount of time that can elapse in a pattern-matching operation before the operation times out. |
pattern | This field is used by a Regex object generated by the CompileToAssembly method. |
roptions | This field is used by a Regex object generated by the CompileToAssembly method. |
Table: Fields in Regex Class in C#
The different properties and their description is given as follows:
Properties | Description |
|---|---|
CacheSize | This property gets or sets the maximum number of entries in the current static cache of compiled regular expressions. |
CapNames | This property gets or sets a dictionary that maps named capturing groups to their index values. |
Caps | This property gets or sets a dictionary that maps numbered capturing groups to their index values. |
MatchTimeout | This property gets the time-out interval of the current instance. |
Options | This property gets the options that were passed into the Regex constructor. |
RightToLeft | This property gets a value that indicates whether the regular expression searches from right to left. |
Table: Properties in Regex Class in C#
Source: MSDN
The different methods and their description is given as follows:
Methods | Description |
|---|---|
CompileToAssembly(RegexCompilationInfo[], AssemblyName) | This method compiles one or more specified Regex objects to a named assembly. |
Equals(Object) | This method determines whether the specified object is equal to the current object. |
Escape(String) | This method escapes a minimal set of characters (\, *, +, ?, |, {, [, (,), ^, $,., #, and white space) by replacing them with their escape codes. This instructs the regular expression engine to interpret these characters literally rather than as metacharacters. |
GetGroupNames() | This method returns an array of capturing group names for the regular expression. |
GetGroupNumbers() | This method returns an array of capturing group numbers that correspond to group names in an array. |
GetHashCode() | This method serves as the default hash function. |
GetType() | This method gets the Type of the current instance. |
GroupNameFromNumber(Int32) | This method gets the group name that corresponds to the specified group number. |
InitializeReferences() | This method is used by a Regex object generated by the CompileToAssembly method. |
IsMatch(String) | This method indicates whether the regular expression specified in the Regex constructor finds a match in a specified input string. |
IsMatch(String, String, RegexOptions) | This method indicates whether the specified regular expression finds a match in the specified input string, using the specified matching options. |
Match(String) | This method searches the specified input string for the first occurrence of the regular expression specified in the Regex constructor. |
Match(String, Int32) | This method searches the input string for the first occurrence of a regular expression, beginning at the specified starting position in the string. |
Matches(String) | This method searches the specified input string for all occurrences of a regular expression. |
Matches(String, Int32) | This method searches the specified input string for all occurrences of a regular expression, beginning at the specified starting position in the string. |
MemberwiseClone() | This method creates a shallow copy of the current Object. |
Replace(String, MatchEvaluator) | This method replaces all strings that match a specified regular expression with a string returned by a MatchEvaluator delegate. |
Replace(String, MatchEvaluator, Int32) | This method replaces a specified maximum number of strings that match a regular expression pattern with a string returned by a MatchEvaluatordelegate. |
Split(String) | This method splits an input string into an array of substrings at the positions defined by a regular expression pattern specified in the Regex constructor. |
Split(String, Int32) | This method splits an input string a specified maximum number of times into an array of substrings, at the positions defined by a regular expression specified in the Regex constructor. |
ToString() | This method returns the regular expression pattern that was passed into the Regexconstructor. |
Unescape(String) | This method converts any escaped characters in the input string. |
UseOptionC() | This method is used by a Regex object generated by the CompileToAssembly method. |
UseOptionR() | This method is used by a Regex object generated by the CompileToAssembly method. |
ValidateMatchTimeout(TimeSpan) | This method checks whether a time-out interval is within an acceptable range. |
Table: Methods in Regex Class in C#
Source: MSDN
A program that displays all the patterns of one or more digits is given as follows:
using System;
using System.Text.RegularExpressions;
class Example
{
static void Main()
{
Regex regex = new Regex(@"\d+");
MatchCollection match = regex.Matches("The numbers 3 and 5 are prime");
foreach (Match m in match)
{
Console.WriteLine(m);
}
}
}
Source Code: Program that displays all the patterns of one or more digits using regular expressions in C#
The output of the above program is as follows:
3
5
Now let us understand the above program.
The Regex class constructor is used in the above program and it uses a pattern that specifies one or more digits. The code snippet for this is given as follows:
Regex regex = new Regex(@"\d+");
Then the matches method is used that specifies all the occurrences of digits in the given string. Finally these occurrences are printed using the foreach loop. The code snippet for this is given as follows:
MatchCollection match = regex.Matches("The numbers 3 and 5 are prime");
foreach (Match m in match)
{
Console.WriteLine(m);
}
A program that substitutes all the white spaces with underscore is given as follows:
using System;
using System.Text.RegularExpressions;
class Example
{
static void Main()
{
string original_string = "C# is fun";
string replace = "_";
Regex regex = new Regex(@"\s+");
string modified_string = regex.Replace(original_string, replace);
Console.WriteLine("Original String: {0}", original_string);
Console.WriteLine("Modified String: {0}", modified_string);
}
}
Source Code: Program that substitutes all the white spaces with underscore using regular expressions in C#
The output of the above program is as follows:
Original String: C# is fun
Modified String: C#_is_fun
Now let us understand the above program.
The original string is “C# is fun” and all the white spaces in the string need to be replaced with underscore. Then the Regex class constructor is used and it uses a pattern that specifies one or more whitespace characters. The code snippet for this is given as follows:
string original_string = "C# is fun";
string replace = "_";
Regex regex = new Regex(@"\s+");
Then the modified string is created where all the whitespace characters in the original string are replaced by underscore using the Replace() method. Finally, the original string and modified string are printed. The code snippet for this is given as follows:
string modified_string = regex.Replace(original_string, replace);
Console.WriteLine("Original String: {0}", original_string);
Console.WriteLine("Modified String: {0}", modified_string);