Skip to content
Related Articles

Related Articles

JavaScript RegExp Complete Reference

Improve Article
Save Article
  • Last Updated : 23 Nov, 2022
Improve Article
Save Article

The RegExp stands for Regular Expression. A regular expression is a sequence of characters that forms a search pattern. The search pattern can be used for text search and text to replace operations. A regular expression can be a single character or a more complicated pattern.

Syntax:

new RegExp("(Regular Expressioncharactersnonword)")

Example: This example searches the words whose starting character is “A” and ending character is “C” with only one character in between them.

HTML




<!DOCTYPE html>
<html>
   <body style="text-align:center">
      <h1 style="color:green">
         GeeksforGeeks
      </h1>
      <h2>RegExp . Metacharacter</h2>
      <p>
         Input String: ABC, A3C, A C, AXXCC!
      </p>
      <button onclick="geek()">
      Click it!
      </button>
      <p id="app"></p>
      <script>
         function geek() {
             var str1 = "ABC, A3C, A C, AXXCC!";
             var regex4 = /A.C/g;
             var match4 = str1.match(regex4);
           
             document.getElementById("app").innerHTML =
                         "Found " + match4.length
                         + " matches: " + match4;
         }
      </script>
   </body>
</html>

Output:

 

The complete list of JavaScript RegExp is listed below:

JavaScript RegExp

Description

JavaScript RegExp . MetacharacterThe RegExp . Metacharacter in JavaScript is used to search single characters, except line terminator or newline.
JavaScript RegExp m ModifierThe RegExp m Modifier in JavaScript is used to perform multiline matching.
JavaScript RegExp \r MetacharacterThe RegExp \r Metacharacter in JavaScript is used to find the carriage return character (Carriage return means to return to the beginning of the current line without advancing downward).
JavaScript RegExp (x|y) ExpressionThe RegExp (x|y) Expression in JavaScript is used to search any of the specified characters (separated by |).
JavaScript RegExp \xxx MetacharacterThe RegExp \xxx Metacharacter in JavaScript is used to find the character specified by an octal number xxx.
JavaScript RegExp \W MetacharacterThe RegExp \W Metacharacter in JavaScript is used to find the non word character i.e. characters which are not from a to z, A to Z, 0 to 9. It is thethatthe  same as [^a-zA-Z0-9].
JavaScript RegExp [^abc] ExpressionThe RegExp [^abc] Expression in JavaScript is used to search for any character which is not between the brackets.
JavaScript RegExp g ModifierThe RegExp g Modifier in JavaScript is used to find all the occurrences of the pattern instead of stopping after the first match i.e it performs a global match.
JavaScript RegExp [0-9] ExpressionThe RegExp [0-9] Expression in JavaScript is used to search any digit which is between the brackets.
JavaScript RegExp \s MetacharacterThe RegExp \s Metacharacter in JavaScript is used to find the whitespace characters. 
JavaScript RegExp \b MetacharacterThe RegExp \b Metacharacter in JavaScript is used to find a match at the beginning or end of a word
JavaScript RegExp i ModifierThe RegExp i Modifier in JavaScript is used to perform case-insensitive matching in the string.
JavaScript RegExp \n MetacharacterThe RegExp \n Metacharacter in JavaScript is used to find the newline character.
JavaScript RegExp [^0-9] ExpressionThe RegExp [^0-9] Expression in JavaScript is used to search for any digit which is not between the brackets.
JavaScript RegExp \B MetacharacterThe RegExp \B Metacharacter in JavaScript is used to find a match that is not present at the beginning or end of a word.
JavaScript RegExp \f MetacharacterThe RegExp \f Metacharacter in JavaScript is used to find the form feed character (form feed is a page-breaking ASCII control character).
JavaScript RegExp \w MetacharacterThe RegExp \w Metacharacter in JavaScript is used to find the word character i.e. characters from a to z, A to Z, 0 to 9. It is the same as [a-zA-Z_0-9].
JavaScript RegExp \d MetacharacterThe RegExp \d Metacharacter in JavaScript is used to search digit characters. It is the same as [0-9].
JavaScript RegExp \t MetacharacterThe RegExp \t Metacharacter in JavaScript is used to find the tab character. If it is found it returns the position else it returns -1.
JavaScript RegExp \D MetacharacterThe RegExp \D Metacharacter in JavaScript is used to search non-digit characters i.e all the characters except digits. It is the same as [^0-9].
JavaScript RegExp \0 MetacharacterThe RegExp \0 Metacharacter in JavaScript is used to find the NULL character. If it is found it returns the position else it returns -1.
JavaScript RegExp \v MetacharacterThe RegExp \v Metacharacter in JavaScript is used to find the vertical tab character. If it is found it returns the position else it returns -1.
JavaScript RegExp * QuantifierThe RegExp m* Quantifier in JavaScript is used to find the match of any string that contains zero or more occurrences of m.
JavaScript RegExp {X,} QuantifierThe RegExp m{X, } Quantifier in JavaScript is used to find the match of any string that contains a sequence of m, at least X times, where X is a number.
JavaScript RegExp ?! QuantifierThe RegExp ?!m Quantifier in JavaScript is used to find the match of any string which is not followed by a specific string m.
JavaScript RegExp {X} QuantifierThe RegExp m{X} Quantifier in JavaScript is used to find the match of any string that contains a sequence of m, X times where X is a number.
JavaScript RegExp ^ QuantifierThe RegExp ^m Quantifier in JavaScript is used to find the match of any string which contains m at the beginning of it.
JavaScript RegExp ? QuantifierThe m? a quantifier in JavaScript is used to find the match of any string that contains zero or one occurrence of m.
JavaScript RegExp $ QuantifierThe RegExp m$ Quantifier in JavaScript is used to find the match of any string which contains m at the end of it.
JavaScript RegExp + QuantifierThe m+ Quantifier in JavaScript is used to find the match of any string that contains at least one m.
JavaScript RegExp \uxxxx MetacharacterThe RegExp \uxxxx Metacharacter in JavaScript is used to find the Unicode character specified by a hexadecimal number XXXX.
JavaScript RegExp {X,Y} QuantifierThe RegExp m{X, Y} Quantifier in JavaScript is used to find the match of any string that contains a sequence of m, X to Y times where X, Y must be numbered.
JavaScript RegExp toString() MethodThe RegExp toString() Method in JavaScript is used to return the string value of the regular expression.
JavaScript RegExp test() MethodThe RegExp test() Method in JavaScript is used to test for the match in a string. If there is a match this method returns true else it returns false.
JavaScript RegExp ignoreCase PropertyThe RegExp ignoreCase property in JavaScript is used to specify whether the “i” modifier is set or not
JavaScript RegExp constructorThe RegExp constructor in JavaScript is used to return the function that created the RegExp

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!