Sunday, July 27, 2008

What is DLR?

Yes, this is a new name heard by me. I am very much beginner for DLR. I know little about DLR and the same sharing with you.

DLR stands for Dynamic Language Runtime, it would be a layer top on the CLR.

For more detail, must look these links:-

http://geekswithblogs.net/ranganh/archive/2008/07/24/dlr-hosting.aspx
http://blogs.msdn.com/seshadripv/
http://www.codeplex.com/sdlsdk
http://blogs.msdn.com/hugunin/archive/2007/04/30/a-dynamic-language-runtime-dlr.aspx

How to shuffle results - SqlServer?

This is an interesting question asked by Mr. Ram Nath Rao.
The history is:

Mr. Nath wants to shuffle his record(s) every time when the page refreshes, the same has been tried with the use of rand() function by him. Unfortunately, the results were not as expected.

Now, lets elaborate some of interesting points towards this :

When anybody use rand() function what happened [check followings)]:

Select rand()as Random Number --creates random number

The result may be:



When you will repeat above statement, the new result is entirely different from the earlier one.

Now, try another similar query:

Select rand()as Random_Number,* from Employees

The result may be:



In above, result note-down first column Random_Number, this column has the similar value through-out the result.

In another words from above, we can sum-it up that the rand() function, generates a random number which is a new every time we press or execute the query.

Also, it doesn't change with rows when result-set retrieves more than one row(s). So, the problem of Mr. Ram Nath Rao doesn't resolve with the use of rand() function.

I recommended newid() to retrieve the solution of Mr. Ram's problem.

Check the following query:

Select newid()as RowId,* from Employees

Above generates following result(s):-



Note-down first column of above result(s), every row has a new value.

Now, lets try to ad-more stuff in above:

Select newid()as RowId,* from Employees order by newid()



Now, regenerate above result(s) one more time, you can get different resul(s). This is the solution of the problem.

The above is a short-description how we can get random data in SqlServer2000.

Its time to do all above at application-level, I have decided to use Vs2005:

Step(s) to use:

1. Start your Vs2005
2. Create a New Website project named its as 'Shuffle Result'.
3. Rename your default web-page to 'shuffleresults.aspx'
4. Write the following lines



5. Press F7 or choose code-view from Solution-Explorer
6. Add following sort-of-code in 'shuffleresults.aspx.cs'



7. Run the above application by pressing F5.
8. It will generate following result(s):



This is the normal output.

9. Click on 'Shuffle Results' button and check the output it might be s following :



The above is described "How one can shuffle the result-sets".

Sunday, July 20, 2008

How to review .net application?

This is not the end when any application has been developed. After development there are many steps which must have to pass by an application. The same process is know as Code-Review process.

Here are certain guidelines which are assembled by me for my work, I hope these will suits you. Your comments and further guidelines will recoupe our stuffs.



This is just a snapshot the guidelines due to limited resources I am unable to write here all document. You can collect the document by sending me a mail :
gUnderscorearoraAthotmailDotcom with subject: Guidelines-Code-Review.

Sunday, July 13, 2008

Database object naming conventions - SQLSERVER

Database object naming conventions

There is no such hard and fast rule to define database names, but I prefer to use some naming conventions which will polish your task(s):

I always usee the following(s):-

1. Tables
Tables represent the instances of an entity. For example, you store all your customer information in a table. Here, 'customer' is an entity and all the rows in the customers table represent the instances of the entity 'customer'. So, why not name your table using the entity it represents, 'Customer'. Since the table is storing 'multiple instances' of customers, make your table name a plural word.

Rules: Pascal notation; end with an ‘s’
Examples: Employees, Customers, Headlines, Groups etc.

This is a more natural way of naming tables, when compared to approaches which name tables as tblCustomers, tbl_Orders. Further, when you look at your queries it's very obvious that a particular name refers to a table, as table names are always preceded by FROM clause of the SELECT statement.

If your database deals with different logical functions and you want to group your tables according to the logical group they belong to, it won't hurt prefixing your table name with a two or three character prefix that can identify the group.

2. Views
A view is nothing but a table, for any application that is accessing it. So, the same naming convention defined above for tables, applies to views as well, but not always. Here are some exceptions:

a) Views not always represent a single entity. A view can be a combination of two tables based on a join condition, thus, effectively representing two entities. In this case, consider combining the names of both the base tables. Here's an example:

If there is a view combining two tables 'Customers' and 'Addresses', name the view as 'CustomersAddresses'. Same naming convention can be used with junction tables that are used to link two many-to-many related base tables. Most popular example is the 'TitleAuthor' table from 'Pubs' database of SQL Server.

b) Views can summarize data from existing base tables in the form of reports. You can see this type of views in the 'Northwind' database that ships with SQL Server 7.0 and above. Here's the convention that database follows. (I prefer this):

'Product Sales for 1997'
'Summary of Sales by Quarter'
'Summary of Sales by Year'

However, try to stay away from spaces within object names.

3. Stored Procedure
Stored procedures always do some work for you, they are action oriented. So, let their name describe the work they do. So, use a verb to describe the work.

This is how I would name a stored procedure that fetches me the customer details given the customer identification number:
'GetCustomerDetails'. Similarly, you could name a procedure that inserts a new customer information as 'InsertCustomerInfo'. Here are some more names based on the same convention: 'WriteAuditRecord', 'ArchiveTransactions', 'AuthorizeUser' etc.

As explained above in the case of tables, you could use a prefix, to group stored procedures also, depending upon the logical group they belong to. For example, all stored procedures that deal with 'Order processing' could be prefixed with ORD_ as shown below:

ORD_InsertOrder
ORD_InsertOrderDetails
ORD_ValidateOrder

If you are using Microsoft SQL Server, never prefix your stored procedures with 'sp_', unless you are storing the procedure in the master database. If you call a stored procedure prefixed with sp_, SQL Server always looks for this procedure in the master database. Only after checking in the master database (if not found) it searches the current database.

I do not agree with the approach of prefixing stored procedures with prefixes like 'sproc_' just to make it obvious that the object is a stored procedure. Any database developer/DBA can identify stored procedures as the procedures are always preceded by EXEC or EXECUTE keyword

Rules: sp_[_]<table/logical instance>
Examples: spOrders_GetNewOrders, spProducts_UpdateProduct

4. User Defined Functions
In Microsoft SQL Server 2000, User Defined Functions [UDFs] are almost similar to stored procedures, except for the fact that UDFs can be used in SELECT statements. Otherwise, both stored procedures and UDFs are similar. So, the naming conventions discussed above for stored procedures, apply to UDFs as well. You could even use a prefix to logically group your UDFs. For example, you could name all your string manipulation UDFs as shown below:

str_MakeProperCase
str_ParseString

5. Triggers
Though triggers are a special kind of stored procedures, it won't make sense to follow the same naming convention as we do for stored procedures.

While naming triggers we have to extend the stored procedure naming convention in two ways:

a) Triggers always depend on a base table and can't exist on their own. So, it's better to link the base table's name with the trigger name

b) Triggers are associated with one or more of the following operations: Insert, Update, Delete. So, the name of the trigger should reflect it's nature

Rules: TR_<TableName>_
Examples: TR_Orders_UpdateProducts
Notes: The use of triggers is discouraged

6. Indexes
Just like triggers, indexes also can't exist on their own and they are dependent on the underlying base tables. So, again it makes sense to include the 'name of the table' and 'column on which it's built' in the index name. Further, indexes can be of two types, clustered and nonclustered. These two types of indexes could be either unique or non-unique. So, the naming convention should take care of the index types too.
Rules: IX_<TableName>_
Examples: IX_Products_ProductID

7. Columns
Columns are attributes of an entity, that is, columns describe the properties of an entity. So, let the column names be meaningful and natural.

Here's a simplest way of naming the columns of the Customers table:

CustomerID
CustomerFirstName
CustomerAddress

As shown above, it'll be a good idea to prefix the column names with the entity that they are representing.

Here's another idea. Decide on a standard two to four character code for each table in your database and make sure it's unique in the database. For example 'Cust' for Customers table, 'Ord' for Orders tables, 'OrdD' for OrderDetails table, 'Adt' for Audit tables etc. Use this table code to prefix all the column names in that table. Advantage of this convention is that in multi-table queries involving complex joins, you don't have to worry about ambiguous column names, and don't have to use table aliases to prefix the columns. It also makes your queries more readable.

If you have to name the columns in a junction/mapping table, concatenate the table codes of mapped tables, or come up with a new code for that combination of tables.

So, here's how the CustomerID column would appear in Customers table:

Cust_CustomerID

The same CustomerID column appears in the Orders table too, but in Orders table, here's how it's named:

Ord_CustomerID

Some naming conventions even go to the extent of prefixing the column name with it's data type. But I don't like this approach, as I feel, the DBA or the developer dealing with these columns should be familiar with the data types these columns belong to.

If a column references another table’s column, name it <table name>ID
Example: The Customers table has an ID column
The Orders table should have a CustomerID column

8. Uer Defined DataTypes
User defined data types are just a wrapper around the base types provided by the database management system. They are used to maintain consistency of data types across different tables for the same attribute. For example, if the CustomerID column appears half a dozen tables, you must use the same data type for all the occurrences of the CustomerID column. This is where user defined data types come in handy. Just create a user defined data type for CustomerID and use it as the data type for all the occurrences of CustomerID column.

So, the simplest way of naming these user defined data types would be:
Column_Name + '_type'.
So, I would name the CustoerID type as:

CustomerID_type

9. Primary Keys
Primary key is the column(s) that can uniquely identify each row in a table. So, just use the column name prefixed with 'pk_' + 'Table name' for naming primary keys.

Rules: PK_<TableName>
Examples: PK_Products

10. Foreign Keys
Foreign key are used to represent the relationships between tables which are related. So, a foreign key can be considered as a link between the 'column of a referencing table' and the 'primary key column of the referenced table'.

I prefer the following naming convention for foreign keys:

fk_referencing table + referencing column_referenced table + referenced column.

Based on the above convention, I would name the foreign key which references the CustomerID column of the Customers table from the Order's tables CustomerID column as:

fk_OrdersCustomerID_CustomersCustomerID

Foreign key can be composite too, in that case, consider concatenating the column names of referencing and referenced tables while naming the foreign key. This might make the name of the foreign key lengthy, but you shouldn't be worried about it, as you will never reference this name from your code, except while creating/dropping these constraints.

Rules: FK_<TableName1>_<TableName2>
Example: FK_Products_Orderss

11. Defaults and Check Constrains
Use the column name to which these defaults/check constraints are bound to and prefix it with 'def' and 'chk' prefixes respectively for Default and Check constraints.
I would name the default constraint for OrderDate Column as def_OrderDate and the check constraint for OrderDate column as chk_OrderDate.

Rules: DF_<TableName>_
Example: DF_Products_Quantity

12. Variable
For variables that store the contents of columns, you could use the same naming convention that we used for Column names.

13. General Rules
a)Do not use spaces in the name of database objects.
b)Do not use SQL keywords as the name of database objects. In cases where this is necessary, surround the object name with brackets, such as [Year]
c)Do not prefix stored procedures with ‘sp_’ Prefix table names with the owner name.

13. Strucure
a) Each table must have a primary key
o In most cases it should be an IDENTITY column named ID
b) Normalize data to third normal form
o Do not compromise on performance to reach third normal form. Sometimes, a little denormalization results in better performance.
c) Do not use TEXT as a data type; use the maximum allowed characters of VARCHAR instead
d) In VARCHAR data columns, do not default to NULL; use an empty string instead
e) Columns with default values should not allow NULLs
f) As much as possible, create stored procedures on the same database as the main tables they will be accessing.

14. Formatting
· Use upper case for all SQL keywords
o SELECT, INSERT, UPDATE, WHERE, AND, OR, LIKE, etc.
· Indent code to improve readability
· Comment code blocks that are not easily understandable
o Use single-line comment markers(--)
o Reserve multi-line comments (/*.. ..*/) for blocking out sections of code
· Use single quote characters to delimit strings.
o Nest single quotes to express a single quote or apostrophe within a string
 For example, SET @sExample = 'SQL''s Authority'
· Use parentheses to increase readability
o WHERE (color=’red’ AND (size = 1 OR size = 2))
· Use BEGIN..END blocks only when multiple statements are present within a conditional code segment.
· Use one blank line to separate code sections.
· Use spaces so that expressions read like sentences.
o fillfactor = 25, not fillfactor=25
· Format JOIN operations using indents
o Also, use ANSI Joins instead of old style joins4
· Place SET statements before any executing code in the procedure.


15. Coding
· Optimize queries using the tools provided by SQL Server5
· Do not use SELECT *
· Return multiple result sets from one stored procedure to avoid trips from the application server to SQL server
· Avoid unnecessary use of temporary tables
o Use 'Derived tables' or CTE (Common Table Expressions) wherever possible, as they
perform better.
· Avoid using <> as a comparison operator
o Use ID IN(1,3,4,5) instead of ID <> 2
· Use SET NOCOUNT ON at the beginning of stored procedures7
· Do not use cursors or application loops to do inserts8
o Instead, use INSERT INTO
· Fully qualify tables and column names in JOINs
· Fully qualify all stored procedure and table references in stored procedures.
· Do not define default values for parameters.
o If a default is needed, the front end will supply the value.
· Do not use the RECOMPILE option for stored procedures.
· Place all DECLARE statements before any other code in the procedure.
· Do not use column numbers in the ORDER BY clause.
· Do not use GOTO.
· Check the global variable @@ERROR immediately after executing a data manipulation statement (like INSERT/UPDATE/DELETE), so that you can rollback the transaction if an error occurs
o Or use TRY/CATCH
· Do basic validations in the front-end itself during data entry
· Off-load tasks, like string manipulations, concatenations, row numbering, case conversions, type conversions etc., to the front-end applications if these operations are going to consume more CPU cycles on the database server
· Always use a column list in your INSERT statements.
o This helps avoid problems when the table structure changes (like adding or dropping a column).
· Minimize the use of NULLs, as they often confuse front-end applications, unless the applications are coded intelligently to eliminate NULLs or convert the NULLs into some other form.
o Any expression that deals with NULL results in a NULL output.
o The ISNULL and COALESCE functions are helpful in dealing with NULL values.
· Do not use the identitycol or rowguidcol.
· Avoid the use of cross joins, if possible.
· When executing an UPDATE or DELETE statement, use the primary key in the WHERE condition, if possible. This reduces error possibilities.
· Avoid using TEXT or NTEXT datatypes for storing large textual data.9
o Use the maximum allowed characters of VARCHAR instead
· Avoid dynamic SQL statements as much as possible.10
· Access tables in the same order in your stored procedures and triggers consistently.
· Do not call functions repeatedly within your stored procedures, triggers, functions and batches.
· Default constraints must be defined at the column level.
· Avoid wild-card characters at the beginning of a word while searching using the LIKE keyword, as these results in an index scan, which defeats the purpose of an index.
· Define all constraints, other than defaults, at the table level.
· When a result set is not needed, use syntax that does not return a result set.
· Avoid rules, database level defaults that must be bound or user-defined data types. While these are legitimate database constructs, opt for constraints and column defaults to hold the database consistent for development and conversion coding.
· Constraints that apply to more than one column must be defined at the table level.
· Use the CHAR data type for a column only when the column is non-nullable.14
· Do not use white space in identifiers.
· The RETURN statement is meant for returning the execution status only, but not data.

What is the result when comparing two nulls in SQL?

The answer is quite interesting with my stuff. Let me clear it in more writting:

1. When we compare two nulls then the result always 'false'. The main reason is the null is not a value its neither an empty nor a empty space, so the actual result is null which places as null.
2. When we compare a null with another which has some value like some int value then the result is false. The actual result is false and not null.

Consider the following examples:

--null = null is null which is false
Declare @intNull1 int
Set @intNull1 =null
Declare @intNull2 int
Set @intNull2=null
If @intNull1=@intNull2
Print 'null = null is true'
Else
Print 'null = null is false'

--Now assign some value
Set @intNull1 = 1
If @intNull1=@intNull2
Print 'null = int value is true'
Else
Print 'null = int value is false'

Saturday, July 12, 2008

What is difference between Union and Union All?

I have a got a comment and a question from an anonymous for my post How to Insert multiple rows?. I must say thanks to you all to encourage my stuffs.

Union vs. Union All
In simple we can say that
1. union is used to select distinct values from two tables,where as union all is used to select all values including duplicates from the tables.
2. The UNION operator allows you to combine the results of two or more SELECT statements into a single result set. The result sets combined using UNION must all have the same structure. They must have the same number of columns, and the corresponding result set columns must have compatible data types.By default, the UNION operator removes duplicate rows from the result set. If you use UNION ALL, all rows are included in the results and duplicates are not removed.

Lets consider following examples:

1. UNION
Select * from dbo.checkDuplicate
Union --it will leave the duplicate rows
Select * from dbo.checkDuplicate

The above querry will retrieve all rows from checkduplicate table except duplicate entries.

2. UNION ALL
Select * from dbo.checkDuplicate
Union --it will select all rows including duplicates
Select * from dbo.checkDuplicate

The above querry will select all rows from checkduplicate table including duplicate entries.

Note: One can count the number of rows using following statement:

SELECT rows FROM sysindexes WHERE id = OBJECT_ID('checkDuplicate') AND indid < 2

What are New Features in Vs 2008 and .Net Framework 3.5?

Vs 2008 and .Net Framework 3.5 [code name is Orcas] has many new features and improvements prior versions.

The following are some of the features:

1. VS 2008 Multi-Targeting Support
VS 2008 support multiple versions .net framework i.e 2.0, 3.0, 3.5. Where VS 2002 supports only .Net 1.0, VS 2003 supports 1.1, and VS 2005 supports 2.0 . That means you can open an existing project or create a new one with VS 2008, you can pick which version of the .NET Framework to work with - and the IDE will update its compilers and feature-set to match this. And that features, controls, projects, item-templates, and assembly references that not work with that version of the framework will be hidden. Unfotunately it does not support .net1.0 and .net 1.1. but we can run VS 2008 side by side with VS 2005 , VS 2003 and VS 2002 on the same machine.


2. JavaScript Intellisense
I really like this feature. When ever I am writing java script in previous versions , i think about intellisense of java script. Now i got this feature in VS 2008. Now i can enjoy the coding of javascript. This makes developer easy write of coding java script. This built in support of javascript intellisense avoids java script errors and makes developing the code faster.


3. JavaScript Debugging

Now, you can stop putting alerts in your code unnecessarly to check the values of the variable or flow of control. Instead of alert boxes , now you can keep break points to look the values of the variables at client script within your server-side .aspx and .master source files. Its like putting break points in server script.
Any JavaScript breakpoints you set will be saved auto matically in VS 2008 when you close the project/solution. When you open up the project again, the previous locations you set the breakpoints on will still have them enabled.

4. Support of AJAX

One of the main features of VS 2008 is ASP.NET AJAX Control Extenders. These controls are derived from the System.Web.UI.ExtenderControl base class, and which can be used to add additional functionality [usually AJAX or JavaScript support] to existing controls already declared on a page. They enable developers to nicely encapsulate UI behavior, and make it really easy to add richer functionality to an application.


5. Split of Design view and Source view Editing

In VS 2005 and previous versions , we have design view , source view .Besides this features it supports a new "split-view" mode when working on pages. This allows you to see both the HTML source and the Design View at the same-time, and easily have any changes you make in one view be updated in the other. We can set the split view as horizontal as well as vertical to use maximum screen.


6. CSS Manager

VS 2008 supports a new tool window inside the IDE called "Manage Styles". This shows all of the CSS stylesheets, and their corresponding rules, for the page you are currently editing. It can be used both when you are in design-view, as well as when you are in source view on a page.


7. Nested Master Pages

The great feature in asp.net 2.0 is Master page. By including master page we can avoid redundant code like header , footer and menus which contains in all pages. Now in VS 2008,we can create nested master pages.


8. List View Control

One of the new controls in ASP.NET 3.5 is the control. The ListView control supports the data editing, insertion, deleting, paging and sorting semantics of higher-level controls like the GridView. But - unlike the GridView - it provides you with complete control over the html markup generated.

How to Insert Multiple Records Using Single Insert - SQL SERVER

This is very interesting question, I have received from one of my colleague - Neeraj Tomar. How can I insert multiple values in table using only one insert? .

To insert values in a table, there are many ways like :

Use HrnPayroll --Change database name with yours

--Here you can try with any table available under above chosen database

INSERT INTO dbo.employees VALUES('0001', 'Gaurav','Arora',38)
INSERT INTO dbo.employees VALUES('0005', 'Shuby','Arora',28)
INSERT INTO dbo.employees VALUES('0007', 'Shweta','Arora',29)

Go

With the help of above lines, one can achieve the task but think for numerous insert statements to do the same one should repeat the Insert multiple times.

--One can achieve the multiple insertion with the following statement:
Insert Into dbo.employees (ID, FirstName, LastName, Age)
Select '0008','Arun', 'Kumar',39
Union All
Select '0009','Vibha', 'Arora',19
Union All
Select '0018','Neeraj', 'Tomar',23
Union All
Select '0118','Laxmi', 'Farswan',24

Go

With the help of above line one can insert multiple data using single Insert statement. The above both statements are working fine when using SQLSerevr 2000/2005.

The SQLServer2008 provides more stuff to add multiple values using single Insert statement.


--The following querry will happen only with SQLServer2008:
Insert Into dbo.employees (ID, FirstName, LastName, Age)
Values('1018','Neeraj', 'Shivasam',18)
Values('1118','Neeraj', 'Huda',38)
Values('1028','Gaurav', 'Malhotra',30)
Values('1128','Abhishek', 'Prasad',30)
Values('2128','Pankaj', 'Nautiyal',36)
Values('3128','Ritesh', 'Kashyap',33)

Sunday, July 6, 2008

What are different IIS isolation levels?

IIS has three levels of isolations :


LOW (IIS Process)
In this main IIS process and ASP.NET application run in the same process. SO, if any one crashes the other is also affected. Example lets say I have hosted Yahoo Hotmail, Amazon and Google on a single PC. So, all applications and IIS process runs on the same process. In case any website crashes it affects everyone.


MEDIUM (Pooled)
In Medium pooled scenario the IIS and Web-application runs in different process. So, in this case there are two processes: process1 and process2. In Proess1 the IIS process is running and in Process2 we have all web-applications running.


HIGH (Isolated)
In High Isolated scenario every process is running in their own process. This consumes heavy memory but has highest reliability.

Saturday, July 5, 2008

Regular Expressions - How to use?

Yesterday, my colleague Kumar Abhishek asked me to draft a Regular expression to validate url like : regularexp.indotnet.com, he was bit confused to draft the same as he wan't aware the power of regular expression. The following lines are for Kumar Abhishek


The following are special characters when working with Regular Expressions.
They will be discussed throughout the article.

. $ ^ { [ (  ) * + ? \

Matching any character with dot - The Period sign [.]


The full stop or period character (.) is known as dot. It is a
wildcard that will match any character except a new line (\n). For
example
if I wanted to match the 'g' character followed by any two characters.


Text: gau shu gnt cow
Regex: g..
Matches: gau shu gnt cow
gau
gnt

If the Singleline option is enabled, a dot matches any character
including the new line character.


Matching word characters - The Word sign [w]


Backslash and a lowercase 'w' (\w) is a character class that
will match any word character. The following Regular Expression matches 'a'
followed by two word characters.

Text: abc anaconda ant cow apple
Regex: a\w\w
Matches: abc anaconda ant cow apple
abc
ana
ant
app

Backslash and an uppercase 'W' (\W) will match any non-word
character.


Matching white-space - The Space sign [s]


White-space can be matched using \s (backslash and 's').
The following Regular Expression matches the letter 'a' followed by two word
characters then a white space character.

Text: "abc anaconda ant"
Regex: a\w\w\s
Matches:
"abc "

Note that ant was not matched as it is not followed by a white space
character.


White-space is defined as the space character, new line (\n),
form feed (\f), carriage return (\r), tab
(\t) and vertical tab (\v). Be careful using \s as it
can lead to unexpected behaviour by matching line breaks (\n and
\r). Sometimes it is better to explicitly specify the characters to
match instead of using \s. e.g. to match Tab and Space use
[\t\0x0020]


Matching digits - The Digit sign [s]


The digits zero to nine can be matched using \d (backslash and
lowercase 'd'). For example, the following Regular Expression matches any three
digits in a row.

Text: 123 12 843 8472
Regex: \d\d\d
Matches: 123 12 843 8472
123
843
847

Matching sets of single characters - The Square-Brackets sign [( )]


The square brackets are used to specify a set of single characters to match.
Any single character within the set will match. For example, the following
Regular Expression matches any three characters where the first character is
either 'd' or 'a'.

Text: abc def ant cow
Regex: [da]..
Matches: abc def ant cow
abc
def
ant

The caret (^) can be added to the
start of the set of characters to specify that none of the characters in the
character set should be matched.
The following Regular Expression matches any
three character where the first character is not 'd' and not 'a'.


Text: abc def ant cow
Regex: [^da]..
Matches:
"bc "
"ef "
"nt "
"cow"

Matching ranges of characters - The Hyphen sign [-]


Ranges of characters can be matched using the hyphen (-). the
following Regular Expression matches any three characters where the second
character is either 'a', 'b', 'c' or 'd'.

Text: abc pen nda uml
Regex: .[a-d].
Matches: abc pen nda uml
abc
nda

Ranges of characters can also be combined together. the following Regular
Expression matches any of the characters from 'a' to 'z' or any digit from '0'
to '9' followed by two word characters.


Text: abc no 0aa i8i
Regex: [a-z0-9]\w\w
Matches: abc no 0aa i8i
abc
0aa
i8i

The pattern could be written more simply as [a-z\d]


Specifying the number of times to match with Quantifiers- The Plus and Star sign [+ and *]


Quantifiers let you specify the number of times that an expression must
match. The most frequently used quantifiers are the asterisk character
(*) and the plus sign (+). Note that the asterisk
(*) is usually called the star when talking about Regular
Expressions.


Matching zero or more times with star (*)


The star tells the Regular Expression to match the character, group, or
character class that immediately precedes it zero or more times. This
means that the character, group, or character class is optional, it can be
matched but it does not have to match. The following Regular Expression matches
the character 'a' followed by zero or more word characters.

Text: Anna Jones and a friend owned an anaconda
Regex: a\w*
Options: IgnoreCase
Matches: Anna Jones and a friend owned an anaconda
Anna
and
a
an
anaconda

Matching one or more times with plus (+)


The plus sign tells the Regular Expression to match the character, group, or
character class that immediately precedes it one or more times. This
means that the character, group, or character class must be found at least once.
After it is found once it will be matched again if it follows the first match.
The following Regular Expression matches the character 'a' followed by at least
one word character.

Text: Anna Jones and a friend owned an anaconda
Regex: a\w+
Options: IgnoreCase
Matches: Anna Jones and a friend owned an anaconda
Anna
and
an
anaconda

Note that "a" was not matched as it is not followed by any word characters.


Matching zero or one times with question mark (?)


To specify an optional match use the question mark (?). The
question mark matches zero or one times. The following Regular Expression
matches the character 'a' followed by 'n' then optionally followed by another
'n'.

Text: Anna Jones and a friend owned an anaconda
Regex: an?
Options: IgnoreCase
Matches: Anna Jones and a friend owned an anaconda
An
a
an
a
an
an
a
a

Specifying the number of matches


The minimum number of matches required for a character, group, or character
class can be specified with the curly brackets ({n}). The
following Regular Expression matches the character 'a' followed by a minimum of
two 'n' characters. There must be two 'n' characters for a match to occur.

Text: Anna Jones and Anne owned an anaconda
Regex: an{2}
Options: IgnoreCase
Matches: Anna Jones and Anne owned an anaconda
Ann
Ann

A range of matches can be specified by curly brackets with two numbers inside
({n,m}). The first number (n) is the minimum
number of matches required, the second (m) is the maximum number of matches
permitted. This Regular Expression matches the character 'a' followed by a
minimum of two 'n' characters and a maximum of three 'n' characters.

Text: Anna and Anne lunched with an anaconda annnnnex
Regex: an{2,3}
Options: IgnoreCase
Matches: Anna and Anne lunched with an anaconda annnnnex
Ann
Ann
annn

The Regex stops matching after the maximum number of matches has been
found.


Matching the start and end of a string


To specify that a match must occur at the beginning of a string use the caret
character (^). For example, I want a Regular Expression pattern to
match the beginning of the string followed by the character 'a'.

Text: an anaconda ate Anna Jones
Regex: ^a
Matches: an anaconda ate Anna Jones
"a" at position 1

The pattern above only matches the a in "an".


Note that the caret (^) has different behaviour when used inside
the square brackets.


If the Multiline option is on, the caret (^) will match
the beginning of each line in a multiline string rather than only the start of
the string.


To specify that a match must occur at the end of a string use the dollar
character ($). If the Multiline option is on then the pattern will
match at the end of each line in a multiline string. This Regular Expression
pattern matches the word at the end of the line in a multiline string.

Text: "an anaconda
ate Anna
Jones"
Regex: \w+$
Options: Multiline, IgnoreCase
Matches:
Jones

Finally, here is the Q. & Ans. for Kumar Abhishek

Q. How to write a regular expression to validate following domain name in ASP.NET Ver.1.1
wellatbell.whdev.com
Ans: <asp:regularexpressionvalidator runat="server" controltovalidate="txtDomainName" errormessage="Please enter a Domain in the correct format." validationexpression="^([0-9a-zA-Z])*\.([0-9a-zA-Z])*\.([a-zA-Z]{3})$" cssclass="clsForm" id="revDomainName">****</asp:regularexpressionvalidator>



Hope, the above reading will fulfill your needs. All the best.