\(|\)|\+|\-|\*|/|%|<+|>+|(>=)|(<=)|=|!=|\:|\!\:|([^\(\)\+\-\*/%<>=\!\:])+
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
namespace mathexp
{
public partial class Form1 : Form
{
Regex regex = null;
public Form1()
{
InitializeComponent();
}
private void btnMath_Click(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder();
sb.Append("\\(");
sb.Append("|\\)");
sb.Append("|\\+");
sb.Append("|\\-");
sb.Append("|\\*");
sb.Append("|/");
sb.Append("|%");
sb.Append("|<+");
sb.Append("|>+");
sb.Append("|(>=)");
sb.Append("|(<=)");
sb.Append("|=");
sb.Append("|!=");
sb.Append("|:");
sb.Append("|!:");
// \\+-\\*/(>=)(<=)><(!=)=%
//sb.Append("[^\\-\\+\\*/><=(!=)(>=)(<=)\\(\\)(:has\\(.+?\\))(:not\\(.+?\\)]+");
if (tbRegex.Text.Trim().Length > 0) regex = new Regex(tbRegex.Text.Trim());
else regex = new Regex(sb.ToString());
string exp = tbExp.Text.Trim().ToString();
exps(exp);
}
public void exps(string exp)
{
rtbResult.Text = "";
MatchCollection mc = regex.Matches(exp);
foreach (Match m in mc)
{
rtbResult.Text += m.Groups[0].Value + "\n";
}
}
/// <summary>
/// 算术运算
/// </summary>
/// <param name="exp"></param>
public void Arithmetic(string exp)
{
Regex re1 = new Regex("*/");
Regex re2 = new Regex("+-");
Regex re = new Regex("\\+-\\*/");
}
}
}