WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

JavaScript RegExp Reference


RegExp Object

A normal articulation is an article that portrays an example of characters.

Regular articulations are utilized to perform design coordinating and "search-and-replace" works on text.

Syntax

/pattern/modifiers;

Example

var patt =/welookups/i

Example explained:

  • /welookups/i  is an ordinary expression.
  • welookups  is an example (to be utilized in a search).
  • i  is a modifier (adjusts the inquiry to be case-insensitive).

Modifiers

Modifiers are utilized to perform case-obtuse and worldwide searches:

Modifier Description
i Perform case-obtuse matching
g Perform a worldwide match (discover all matches as opposed to halting after the first match)
m Perform multiline matching

Brackets

Brackets are utilized to discover a scope of characters:

Expression Description
[abc] Find any character between the brackets
[^abc] Find any character NOT between the brackets
[0-9] Find any digit between the brackets
[^0-9] Find any digit NOT between the brackets
(x|y) Find any of the options specified

Metacharacters

Metacharacters are characters with an uncommon meaning:

Metacharacter Description
Find a solitary character, aside from newline or line terminator
\w Find a word character
\W Find a non-word character
\d Find a digit
\D Find a non-digit character
\s Find a whitespace character
\S Find a non-whitespace character
\b Find a match toward the starting/end of a word
\B Find a match not toward the starting/end of a word
\0 Find a NUL character
\n Find another line character
\f Find a structure feed character
\r Find a carriage return character
\t Find a tab character
\v Find a vertical tab character
\xxx Find the character indicated by an octal number xxx
\xdd Find the character indicated by a hexadecimal number dd
\uxxxx Find the Unicode character indicated by a hexadecimal number xxxx

Quantifiers

Quantifier Description
n+ Matches any string that contains no less than one n
n* Matches any string that contains at least zero events of n
n? Matches any string that contains zero or one events of n
n{X} Matches any string that contains an arrangement of X n's
n{X,Y} Matches any string that contains an arrangement of X to Y n's
n{X,} Matches any string that contains an arrangement of at any rate X n's
n$ Matches any string with n toward the finish of it
^n Matches any string with n toward the start of it
?=n Matches any string that is pursued by a particular string n
?!n Matches any string that isn't pursued by a particular string n

RegExp Object Properties

Property Description
constructor Returns the capacity that made the RegExp article's prototype
global Checks whether the "g" modifier is set
ignoreCase Checks whether the "i" modifier is set
lastIndex Specifies the list at which to begin the following match
multiline Checks whether the "m" modifier is set
source Returns the content of the RegExp pattern

RegExp Object Methods

Method Description
compile() Deprecated in form 1.5. Compiles an ordinary expression
exec() Tests for a match in a string. Returns the first match
test() Tests for a match in a string. Returns genuine or false
toString() Returns the string estimation of the normal expression