C# 提取字符串中括号里的值

快乐鱼儿 1年前 ⋅ 1174 阅读

C# 正则表达式提取字符串中括号里的值 :

分别提取不同括号中的值:

string getValue = Regex.Replace(str, @"(.*\()(.*)(\).*)", "$2");  //小括号()
    
Regex rgx = new Regex(@"(?i)(?<=\[)(.*)(?=\])");   //中括号[]
string tmp = rgx.Match(CvoName).Value;  //中括号[]
    
string sheetData = Regex.Match(LinkData, @"\{(.*)\}", RegexOptions.Singleline).Groups[1].Value;  //大括号{}

全部评论: 0

    我有话说: