C# String 檢查 Regular Expression Pattern
using System.Text.RegularExpressions; namespace WindowsFormsApplication1 { public partial class Form1 : Form { … … private void Form1_Load(object sender, EventArgs e) { if (CheckString("user1@yahoo.com", "(?<user>)@(?<host>)")) { label7.Text = "Yes"; }else{ label7.Text = "No"; } } private Boolean CheckString(String input, String Pattern) { Regex emailregex = new Regex(Pattern); Match m = emailregex.Match(input); return m.Success; } } } |