使用C#在Windows应用程序中的正则表达式 [英] regular expression in windows application using C#

查看:77
本文介绍了使用C#在Windows应用程序中的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我正在使用C#开发Windows应用程序.
我们可以在Windows应用程序中使用正则表达式验证吗?怎么样?
我想要一个字符串,该字符串包含按顺序开头5个字符的字母,然后按顺序包含4个字符的数字和1个字符的字母.
问候,
Zuber Kazi

Hello Guys,
I am developing windows application using C#.
Can we use regular expression validation in windows application? How?
I want a string which contain starting 5 char Alphabets then 4 char numeric and 1 char Alphabet in sequence.
Regards,
Zuber Kazi

推荐答案

实际上,是的,可以.
如何:使用正则表达式(C#)搜索字符串 [ ^ ]
C#中的正则表达式用法 [ System.Text.RegularExpressions.Regex类 [ RegExr [
Actually, yes you can.
How to: Search String Using Regular Expressions (C#)[^]
Regular Expressions Usage in C#[^]
System.Text.RegularExpressions.Regex Class[^]

And here is a cool site to find the regex you want and practice a bit with it... RegExr[^] (it''s really easy to use!).
Hope these links can get you on your way! :)


Expresso是测试正则表达式的免费工具,可以从
下载
http://www.ultrapico.com/Expresso.htm [
Expresso is good free tool to test regular expressions and it can be downloaded from

http://www.ultrapico.com/Expresso.htm[^]

In Windows forms, Validating event of control can be used to test the required string with Regex.IsMatch method for the required pattern. If it fails then set e.Cancel = true else set e.Cancel = false

For the pattern mentioned in the question the following regular expression can be used

^[a-zA-Z]{5}\d{4}[a-zA-Z]


这篇关于使用C#在Windows应用程序中的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆