Home > Net >  C # regular expressions
C # regular expressions

Time:09-16

1. Need to write a few regular expressions to extract () [], [], {}, & lt;> Several need contains parentheses in the string, and does not include the parentheses,

CodePudding user response:

Only simple with the help of you, can't match with parentheses inside brackets

 
Public static List The RegexMatch (string input, char cStart, char cEnd, bool isHave)
{
MatchCollection MatchCollection=Regex Matches (input, the string. Format (@ \ {0} "(. *?) The \ {1} ", cStart, cEnd));
List ListResult=new List (a);
Foreach (var v in matchCollection)
{
String strV=v.T oString ();
if (! IsHave)
{
StrV=strV. Trim (new char [] {cStart, cEnd});
}
ListResult. Add (strV);
}
Return listResult;
}

  •  Tags:  
  • C #
  • Related