Monday, 18 January 2016

C# Regular Expression Get Text Between Brackets

//string regularExpressionPattern = @"\<(.*?)\>"; // FOR right angles < >
//string regularExpressionPattern = @"\((.*?)\)"; // FOR parenthesis ( )
//string regularExpressionPattern = @"\{(.*?)\}"; // FOR curly brackets { }

string regularExpressionPattern = @"\[(.*?)\]"; //FOR []

string inputText = "Find string inside brackets [test1] and [test2] in [ASP.net]";

Regex re = new Regex(regularExpressionPattern);

foreach (Match m in re.Matches(inputText))
{
       //Put Your LOGIC
}

No comments:

Post a Comment

Get all non-clustered indexes

DECLARE cIX CURSOR FOR     SELECT OBJECT_NAME(SI.Object_ID), SI.Object_ID, SI.Name, SI.Index_ID         FROM Sys.Indexes SI             ...