RegEx Getting started (1)
Regular Expressions usually have a lot of contact, but most of them are in the form of casual flowers. If you want to search, you will forget to read it. Today, I reviewed the results and wrote them out to my summary:
The following is a simple usage. The complexity will continue tomorrow:
LRegEx. ismatchUsage
//Simply match a word
Console. writeline ( " \ N \ nismatch Demo: " );
RegEx Reg = New RegEx ( " Aaron " );
Console. writeline ( String . Format ( " Result1: {0} " , Reg. ismatch ( " My name is Aaron. " ))); // True
Console. writeline ( String . Format ( " Result2: {0} " , Reg. ismatch ( " My name is Arron. " ))); // False
//The default value is case sensitive, so the following two results will return different results.
Console. writeline ( String . Format ( " Result3: {0} " , RegEx. ismatch ( " My name is Aaron. " , " Aaron " ))); // False
Console. writeline ( String . Format ( " Result4: {0} " , RegEx. ismatch ( " My name is Arron. " , " Aaron " ))); // False
//This is case insensitive.
Console. writeline ( String . Format ( " Result3: {0} " , RegEx. ismatch ( " My name is Aaron. " , " Aaron " , Regexoptions. ignorecase ))); // True
LRegEx. ReplaceUsage
Simply replace a word
// Simply replace a word
Console. writeline ( " \ N \ nreplace Demo: " );
Reg = New RegEx ( " R " );
Console. writeline ( String . Format ( " Result4: {0} " , Reg. Replace ( " My name is Arron. " , " R " ))); // My name is Arron.
Console. writeline ( String . Format ( " Result4: {0} " , Reg. Replace ( " My name is Arron. " , " R " , 1 ))); // Replace only once // My name is Arron.
LRegEx. MatchUsage
//* ********************* Match usage **************** *************
Console. writeline ( " \ N \ nmatch Demo: " );
Reg = New RegEx ( " Aa... " ); // The first two letters must be AA and followed by any 3 Characters
Match m = Reg. Match ( " My name is Aaron, Aaron, Aaron " );
While (M. Success)
{
Console. writeline (M. value );
M = M. nextmatch ();
// The default value is case sensitive.
// Aaron is a match.
// Aaron is also a match
// Aaron won't match
}
LRegEx. matchsUsage
// ******************** ***
Console. writeline ( " \ N \ nmatchscollection Demo: " );
Matchcollection MC = RegEx. Matches ( " My name is Aaron, Aaron, Aaron " , " Aa... " ); // The first two letters must be AA and followed by any 3 Characters
console. writeline ( string . format ( " found: {0} " , MC. count);