정규 표현식 테스터(Regular Expression Tester)
소스가 많이 더럽습니다.
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Text.RegularExpressions; namespace RegexExpression { public partial class Form1 : Form { MatchCollection colMatches; int numSel, nowCount, matchesCount; public Form1() { InitializeComponent(); } private void button3_Click(object sender, EventArgs e) { if (textBox1.Text == string.Empty) return; RegexOptions RegexOption = new RegexOptions(); if (checkBox1.Checked) RegexOption |= RegexOptions.IgnoreCase; if (checkBox2.Checked) RegexOption |= RegexOptions.Multiline; Regex objRegExp = new Regex(textBox1.Text, RegexOption | RegexOptions.Compiled); if (objRegExp.IsMatch(textBox3.Text)) { colMatches = objRegExp.Matches(textBox3.Text); label5.Text = "(1 / " + colMatches.Count + ")"; if (textBox2.Text == string.Empty) { textBox3.Focus(); textBox3.Select(textBox3.Text.IndexOf(colMatches[0].Value), colMatches[0].Value.Length); numSel = textBox3.SelectionStart; matchesCount = colMatches.Count; nowCount = 1; if (colMatches.Count > 1) button2.Enabled = true; else button2.Enabled = false; } else { textBox3.Text = objRegExp.Replace(textBox3.Text, textBox2.Text); button1.Enabled = false; button2.Enabled = false; label5.Text = "(0 / 0)"; } } else { MessageBox.Show("일치하는 텍스트가 없습니다.", "정규 표현식 테스터", MessageBoxButtons.OK, MessageBoxIcon.Error); button1.Enabled = button2.Enabled = false; } } private void button2_Click(object sender, EventArgs e) { if (button1.Enabled == false) button1.Enabled = true; if (matchesCount == nowCount + 1) button2.Enabled = false; textBox3.Focus(); textBox3.SelectionStart = textBox3.Text.IndexOf(colMatches[nowCount].Value, numSel + 2); textBox3.SelectionLength = colMatches[nowCount].Value.Length; numSel = textBox3.SelectionStart; nowCount += 1; label5.Text = "(" + nowCount + " / " + matchesCount + ")"; } private void button1_Click(object sender, EventArgs e) { if (button2.Enabled == false) button2.Enabled = true; if (nowCount - 1 == 1) button1.Enabled = false; textBox3.Focus(); textBox3.SelectionStart = textBox3.Text.LastIndexOf(colMatches[nowCount - 2].Value, numSel - 2); textBox3.SelectionLength = colMatches[nowCount - 2].Value.Length; numSel = textBox3.SelectionStart; nowCount -= 1; label5.Text = "(" + nowCount + " / " + matchesCount + ")"; } } }
'소스 관련' 카테고리의 다른 글
Visual Basic 6으로 만들어진 추첨기 코드 (0) | 2013.02.05 |
---|---|
웹 관련 함수 생성기 (1) | 2013.01.20 |
헤더를 VB6 코드로 쉽게 변환! (HEADER -> VB6 CODE CONVERTER) (2) | 2013.01.02 |
POST 데이터 비교(POST Data Compare) (0) | 2013.01.02 |
VB6 -> C# 포팅, 네이버 로그인, 네이버 쪽지 전송, 네이버 메일 전송 (10) | 2012.12.02 |