Regular Expression in .NET Examples


I will try to guide you step by step on how to write our own regular expression. The purpose of this article is Easily create and understand regular expressions. This will helpful, when we create an application.

Examples of regular expressions


Example No.1

Syntax:

\d{3}


Example: 289

Description: A Three digit number


Example No.2

Syntax:

\w{8,20}


Example: Christopher

Description: At least eight character. But not more than twenty characters.


Example No.3

Syntax:

\d{2}-\d{4}


Example: 10-3944

Description: Two Digit number followed by a hyphen and a four-digit number.


Example No.4

Syntax:

\w{1,8}.\w{1,3}


Example: Sample.jpg

Description: Up to eight letters or numbers,followed by a period and up to three letters or numbers


Example No.5

Syntax:

(AB)|(SB)-\d{1,5}


Example: SB-1234

Description: The letters AB or SB, followed by a hyphen and a 1 to 5 digit number .


Example No.6

Syntax:

\d{5}(-\d{4})?


Example: 93711-2767

Description: A Five digit number,optionally followed by a hyphen and four digit number.


Example No.7

Syntax:

\w*\d\w*


Example: arm02

Description: A text entry that contains at least numeral.


Example No.8

Syntax:

[xyz]\d{3}


Example: x023

Description: The letter x,y, or z followed by a 3 digit number.


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: