.NET Framework Developer Center >
.NET Development Forums
>
.NET Base Class Library
>
Expression Evaluator
Expression Evaluator
Dear All
I couldn't find a method to evaluate a regular expression in C#
Ex: string exp="(3+5)/2-1";
I hope if anyone could hep.
Answers
- They're in System.Text.RegularExpressions.Regex class. Try IsMatch and Match methods.
- Are you really looking for regular expression capabilities, or are you looking to evaluate the math expression you provided as an example to 3? .NET doesn't provided math expression evaluation out of the box. You will either need to look for a library online to provide that functionality or write your own. You could try here.
- An relatively cheap expression evaluator can be found in DataColumn and it's Expression property, eg:
Code SnippetDataTable dt = new DataTable();
DataRow dr = dt.Rows.Add();
DataColumn dc = dt.Columns.Add();
dc.Expression = "(3+5)/2-1";
Console.WriteLine( dr[0] ); - Check out LazyParser.NET, a full-featured lightweight C# expression parser.
All Replies
- They're in System.Text.RegularExpressions.Regex class. Try IsMatch and Match methods.
- Are you really looking for regular expression capabilities, or are you looking to evaluate the math expression you provided as an example to 3? .NET doesn't provided math expression evaluation out of the box. You will either need to look for a library online to provide that functionality or write your own. You could try here.
- An relatively cheap expression evaluator can be found in DataColumn and it's Expression property, eg:
Code SnippetDataTable dt = new DataTable();
DataRow dr = dt.Rows.Add();
DataColumn dc = dt.Columns.Add();
dc.Expression = "(3+5)/2-1";
Console.WriteLine( dr[0] ); - Check out LazyParser.NET, a full-featured lightweight C# expression parser.


