正则截取字符串中的字符。

 

截取"方向正确"

string str="不管前方的路有多苦,只要走的方向正确,不管多么崎岖不平,都比站在原地更接近幸福 "

s="走的";

e=" ,不管"

 

public static string Extract(string str, string s, string e)
{
Regex rg = new Regex("(?<=(" + s + "))[.\\s\\S]*?(?=(" + e + "))", RegexOptions.Multiline | RegexOptions.Singleline);
return rg.Match(str).Value;
}

注意:特殊字符,大小写 中英文对应

posted on 2018-11-06 13:58  苏了个酥i  阅读(9045)  评论(0编辑  收藏  举报