Javascript regular expression

  • 208 views
Uploaded on

 

More in: Education , Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
208
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
10
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. JavaScript Regular Expression
  • 2. • A regular expression is an object that describes a pattern of characters. • regular expressions is used to perform patternmatching and search-and-replace on text.
  • 3. Syntax for Regular Expression • Var pattern=/….Expression …/
  • 4. Examples • Pattern for All lowercase letters var pattern=/[a-z]/ • Pattern for All Uppercase letters var pattern=/[A-Z]/ • Pattern for all letters var pattern=/[a-zA-Z]/ • Pattern for only digits var pattern=/[0-9]/
  • 5. Examples • Pattern for age var pattern=/^d{1,2}$/ • Pattern for mobile number. var pattern=/^d{10}$/;
  • 6. Metacharacter • A metacharacter is simply an alphabetical character preceded by a backslash that acts to give the combination a special meaning.
  • 7. Validation email ID • Var pattern=/^w+([.-]?w+)*@w+([.]?w+)*(.w{2,3})+$/ Characters Description /../ all regular expression start with forward slash ^ w+ .- matches beginning of string matches one or more word char indicate next char is special matches . Or _ and end
  • 8. • Characters ? or 1 time Description Matches previous char 0 ([.-]?w+)* matches 0 or more occurences of [.-]w+ @ matches @only (.w{2,3}) it matches . Followed by 2 or 3 word char
  • 9. • Characters Description + indicates expression occur one or more times e.g. .com, co.us $ matches end of string