// ① Regular Expression => match string text = @ "this is a book, this is my book, is not IIS"; // define a pattern string, it is not just plain text, but also a regular expression string pattern = "is"; matchcollection matches = RegEx. matches (text, pattern, regexoptions. ignorecase | // ignore case-insensitive regexoptions. explicitcapture | // improves the retrieval efficiency. regexoptions. righttoleft // match the string from left to right); console. writeline ("matching string from right to left:"); foreach (match nextmatch in matches) {console. write ("matched position: {0, 2} ", nextmatch. index); console. write ("matched content: {0, 2}", nextmatch. value); console. write ("/N");} console. writeline (); // ② match start with uppercase I // "/B" is an escape sequence, representing the beginning and end (the boundary of a word, ignoring white space or punctuation) pattern = @ "/Bi"; matches = RegEx. matches (text, pattern, regexoptions. explicitcapture // improves the retrieval efficiency); console. writeline ("matching string from left to right:"); foreach (match nextmatch in matches) {console. write ("matched location: {0}", nextmatch. index); console. write ("matched Content: {0} ", nextmatch. value); console. write ("/N");} console. writeline (); // ③ match a string that starts with uppercase I and ends with uppercase S. // "/B" is an escape sequence that represents the start and end of a word (the boundary of a word, ignore blank or punctuation) // s * match any character that is not blank pattern = @ "/Bi/S * s/B"; matches = RegEx. matches (text, pattern, regexoptions. explicitcapture // improves the retrieval efficiency); console. writeline ("matching string from left to right:"); foreach (match nextmatch in matches) {console. write ("matched location: {0}", nextmatch. index); console. write ("matched content: {0}", ne Xtmatch. value); console. write ("/N");} console. writeline (); // ④ match his or IIS, where case-insensitive pattern = @ "[H | I] is"; matches = RegEx. matches (text, pattern, regexoptions. ignorecase | // ignore case-insensitive regexoptions. explicitcapture // improves the retrieval efficiency); console. writeline ("matching string from left to right:"); foreach (match nextmatch in matches) {console. write ("matched location: {0}", nextmatch. index); console. write ("matched content: {0}", nextmatch. value); console. write ("/ N ");} console. writeline (); // ⑤ the URL grouping matches text = "http: // 192.168.0.1: 2008"; pattern = @ "/B (/S + ): // (/S + )(?: :(/S +)/B "; matches = RegEx. matches (text, pattern); console. writeline ("matching string from left to right:"); foreach (match nextmatch in matches) {console. write ("matched location: {0}", nextmatch. index); console. write ("matched content: {0}", nextmatch. value); console. write ("/N"); For (INT I = 0; I <nextmatch. groups. count; I ++) {console. write ("matched group {0 }:{ 1, 4}", I + 1, nextmatch. groups [I]. value); console. write ("/N") ;}} console. read ();