Una piccola utility per testare le proprie Regular
Expressions.
using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;using System.Text.RegularExpressions;namespace RE.Test{ /// <summary> /// Summary description for Form1. /// </summary> public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; private System.Windows.Forms.TextBox textBox2; private System.Windows.Forms.Label label3; private System.Windows.Forms.TextBox textBox3; private System.Windows.Forms.CheckBox checkBox1; /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.Container components = null; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } /// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.textBox1 = new System.Windows.Forms.TextBox(); this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.textBox2 = new System.Windows.Forms.TextBox(); this.label3 = new System.Windows.Forms.Label(); this.textBox3 = new System.Windows.Forms.TextBox(); this.checkBox1 = new System.Windows.Forms.CheckBox(); this.SuspendLayout(); // // textBox1 // this.textBox1.Location = new System.Drawing.Point(112, 12); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(216, 20); this.textBox1.TabIndex = 0; this.textBox1.Text = ""; this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged); // // label1 // this.label1.Location = new System.Drawing.Point(16, 16); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(88, 16); this.label1.TabIndex = 1; this.label1.Text = "RegEx:"; // // label2 // this.label2.Location = new System.Drawing.Point(16, 44); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(88, 16); this.label2.TabIndex = 4; this.label2.Text = "Test:"; // // textBox2 // this.textBox2.Location = new System.Drawing.Point(112, 40); this.textBox2.Name = "textBox2"; this.textBox2.Size = new System.Drawing.Size(216, 20); this.textBox2.TabIndex = 3; this.textBox2.Text = ""; this.textBox2.TextChanged += new System.EventHandler(this.textBox2_TextChanged); // // label3 // this.label3.Location = new System.Drawing.Point(16, 68); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(88, 16); this.label3.TabIndex = 6; this.label3.Text = "Result:"; // // textBox3 // this.textBox3.Location = new System.Drawing.Point(112, 64); this.textBox3.Name = "textBox3"; this.textBox3.Size = new System.Drawing.Size(216, 20); this.textBox3.TabIndex = 5; this.textBox3.Text = ""; // // checkBox1 // this.checkBox1.Checked = true; this.checkBox1.CheckState = System.Windows.Forms.CheckState.Checked; this.checkBox1.Location = new System.Drawing.Point(344, 12); this.checkBox1.Name = "checkBox1"; this.checkBox1.Size = new System.Drawing.Size(104, 20); this.checkBox1.TabIndex = 7; this.checkBox1.Text = "Negate"; // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(452, 99); this.Controls.Add(this.checkBox1); this.Controls.Add(this.textBox3); this.Controls.Add(this.textBox2); this.Controls.Add(this.textBox1); this.Controls.Add(this.label3); this.Controls.Add(this.label2); this.Controls.Add(this.label1); this.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout(false); } #endregion /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.Run(new Form1()); } private void button1_Click(object sender, System.EventArgs e) { docheckit(); } private void docheckit() { // string m_ValidatingExpression = textBox1.Text; RegexOptions m_ValidatingOptions = RegexOptions.None; Regex m_RegularExpression; string validatingValue = textBox2.Text; // try { m_RegularExpression = new Regex( m_ValidatingExpression, m_ValidatingOptions ); // if ( validatingValue == string.Empty ) textBox3.Text = "skip"; if ( m_RegularExpression != null ) { if (checkBox1.Checked) textBox3.Text = ((bool)(! m_RegularExpression.Match( validatingValue.ToString() ).Success)).ToString(); else textBox3.Text = ((bool)(m_RegularExpression.Match( validatingValue.ToString() ).Success)).ToString(); } else textBox3.Text = "skip"; } catch { textBox3.Text = "error"; } } private void textBox1_TextChanged(object sender, System.EventArgs e) { docheckit(); } private void textBox2_TextChanged(object sender, System.EventArgs e) { docheckit(); } }}
Fletto i muscoli e sono nel vuoto.
powered by IMHO