Click here to Skip to main content
14,691,601 members
Articles » Web Development » ASP.NET » General
Article
Posted 21 Mar 2007

Stats

58.5K views
19 bookmarked

Regular Expressions which are needed in daily coding...

Rate me:
Please Sign up or sign in to vote.
2.00/5 (21 votes)
21 Mar 2007GPL3
Regular Expressions for all purpose..

Introduction

Guys , we all know that regular expressions are very useful for checking any kind of patterns.

Background

So we have to know how to write regular expressions for our patterns. But don't worry here i will provide some but very useful regular expressions which will be useful for our coding.

Using the code

just copy and paste Regular Expression from here to your code.
//
// this are the regular expressions for all purposes...
//For checking opening and closing tab of specific HTML tags..
<tt class="regex"><TAG\b[^>]*>(.*?)</TAG></tt>
//for any HTML tags starting and ending..
<tt class="regex"><([A-Z][A-Z0-9]*)\b[^>]*>(.*?)</\1></tt>
//For deleting white spaces from text...
<tt class="regex">^[ \t]+|[ \t]+$</tt>
//For Checking IP address between 0..255...
<tt class="regex">\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.</tt><tt class="regex">(25[0-5]|2[0-4][0-9]|[01]?[0-9]</tt>
<tt class="regex">[0-9]?)\.</tt><tt class="regex">(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.</tt><tt class="regex">
<tt class="regex">(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b</tt><tt class="regex"><tt class="regex"><tt class="regex"> 
//For floating point numbers with sign...
<tt class="regex">[-+]?[0-9]*\.?[0-9]+</tt>
//for floating point numbers with exponents...
<tt class="regex">[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?</tt><tt class="regex"> 
//For email validation...
<tt class="regex">^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$</tt></tt></tt></tt></tt></tt>
<tt class="regex"><tt class="regex"><tt class="regex"><tt class="regex"><tt class="regex"><tt class="regex">//or you can try for .Museum and etc..</tt></tt></tt></tt></tt></tt>
<tt class="regex"><tt class="regex"><tt class="regex"><tt class="regex"><tt class="regex"><tt class="regex">^[A-Z0-9._%-]+@[A-Z0-9.-]+\.(?:[A-Z]{2}|com|org|net|biz|info|name|aero|biz|info|jobs|museum|name)$</tt></tt></tt></tt></tt></tt>
<tt class="regex"><tt class="regex"><tt class="regex"><tt class="regex"><tt class="regex"><tt class="regex">
//Date format for yyyy-mm-dd betwwen 1900-01-01 and 2099-12-31
<tt class="regex">(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])</tt>
<tt class="regex">//Date format for mm/dd/yyyy betwwen 1900-01-01 and 2099-12-31 
<tt class="regex">(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d</tt><tt class="regex"> <tt class="regex"> 
//Date format for dd-mm-yyyy betwwen 1900-01-01 and 2099-12-31 
<tt class="regex">(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\d\d</tt> 
//finding word in a string..
<tt class="regex">^.*\b(one|two|three)\b.*$   //one,two,three may be your words...</tt>
//for deleting duplicate lines from text file...
<tt class="regex">^(.*)(\r?\n\1)+$</tt></tt></tt></tt></tt></tt></tt></tt></tt>
//For checking digits..
^[0-9]
//for checking alphabets...
^[a-z]</tt>
<tt class="regex">//REgular Expression for some Credit cards validations...</tt>
<tt class="regex">
//"Visa"
^[4]([0-9]{15}$|[0-9]{12}$)
//"MasterCard"
^[5][1-5][0-9]{14}$ 

//"Discover" 
^6011-?\\d{4}-?\\d{4}-?\\d{4}$

//"Diners Club" 
(^30[0-5][0-9]{11}$)|(^(36|38)[0-9]{12}$)

//"American Express" 
^[34|37][0-9]{14}$</tt>
<tt class="regex">
//"enRoute"
^(2014|2149)[0-9]{11}$

//"JCB" 
^3[0-9]{15}$)|(^(2131|1800)[0-9]{11}$)</tt>

Points of Interest

I like to Share my knowledge with you, because i am also one of you, taht if i don't know anything then i come to you...so keep excahnge of knowledge...

History

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

Share

About the Author

JustChiragPatel
Software Developer
India India
Chirag Patel, a Programmer Analyst in a well known IT company working on .NET Technologies since last 2 years. He is interested in Pure business logic and fuzzy logic. his area of interest is in C#.NET, VB.NET and MSSQL 2005.

catch me on: http://groups.google.com/group/codewar

Comments and Discussions

 
NewsThere's a new version of the RegEx Tester Tool ! Pin
Pablo Osés2-Mar-08 0:21
MemberPablo Osés2-Mar-08 0:21 
GeneralFormatting issue Pin
Pete O'Hanlon23-Mar-07 0:32
subeditorPete O'Hanlon23-Mar-07 0:32 
GeneralDon't be discouraged Pin
Bradml22-Mar-07 23:46
MemberBradml22-Mar-07 23:46 
QuestionWhat on earth? Pin
NormDroid21-Mar-07 22:57
professionalNormDroid21-Mar-07 22:57 
AnswerRe: What on earth? Pin
purplepangolin22-Mar-07 5:44
Memberpurplepangolin22-Mar-07 5:44 
GeneralRe: What on earth? Pin
NormDroid22-Mar-07 5:50
professionalNormDroid22-Mar-07 5:50 
GeneralRe: What on earth? Pin
purplepangolin22-Mar-07 6:04
Memberpurplepangolin22-Mar-07 6:04 
GeneralRe: What on earth? Pin
NormDroid22-Mar-07 6:48
professionalNormDroid22-Mar-07 6:48 
GeneralRe: What on earth? Pin
purplepangolin22-Mar-07 7:17
Memberpurplepangolin22-Mar-07 7:17 
GeneralRe: What on earth? Pin
JustChiragPatel22-Mar-07 18:31
MemberJustChiragPatel22-Mar-07 18:31 
GeneralRe: What on earth? Pin
NormDroid22-Mar-07 22:42
professionalNormDroid22-Mar-07 22:42 
GeneralRe: What on earth? Pin
NormDroid22-Mar-07 22:41
professionalNormDroid22-Mar-07 22:41 
AnswerRe: What on earth? Pin
ednrgc22-Mar-07 6:20
Memberednrgc22-Mar-07 6:20 
GeneralRe: What on earth? Pin
NormDroid22-Mar-07 6:49
professionalNormDroid22-Mar-07 6:49 
AnswerRe: What on earth? Pin
JustChiragPatel22-Mar-07 18:30
MemberJustChiragPatel22-Mar-07 18:30 
GeneralRe: What on earth? Pin
NormDroid22-Mar-07 22:40
professionalNormDroid22-Mar-07 22:40 
GeneralRe: What on earth? Pin
#realJSOP23-Mar-07 1:25
mva#realJSOP23-Mar-07 1:25 
GeneralRe: What on earth? Pin
NormDroid23-Mar-07 2:19
professionalNormDroid23-Mar-07 2:19 
GeneralRe: What on earth? Pin
#realJSOP24-Mar-07 0:35
mva#realJSOP24-Mar-07 0:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.