| Viewed 97 times

What is a Regular Expression in javascript


What is a Regular Expression in javascript

1 Answer
Mohammad Qandeel
Answered
8

The regular expression used in a search pattern to describe what you are searching for.

A regular expression can be a single character or a more complicated pattern. 

Example 

  var text= "Sample text";
  var pat = /[t]/g; 
  console.log(text.match(pat));// t,t

How to Find any of the digits between the brackets using regular expression

Example

  var text= "123456789";
  var pat = /[1-4]/g; 
  console.log(text.match(pat));//1,2,3,4

 

How to Find a whitespace character using regular expression

Example

  var text= "12 34567 89";
  var pat =  /\s/g;
  console.log(text.match(pat));//" "," "

 

 

 

 

 


Related Questions