Learn regular expressions to locate the metacharacters ^ and $

The ^ character is used to match the beginning of a string, code example

string s = "I am a blue cat.";

string res= Regex.Replace(s, "^", "开始");

Console.WriteLine(res);

Console.ReadKey();

The output is

 

The $ positioning metacharacter is used to match the end of a string, code example

string s = "I am a blue cat.";

string res= Regex.Replace(s, "$", "结束");

Console.WriteLine(res);

Console.ReadKey();

The output is

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325103375&siteId=291194637