JavaScript RegExp
RegExp Modifiers
The following table provides a list of all RegExp
modifiers available in JavaScript.
Modifier | Explanation |
---|---|
i | Perform case-insensitive match and returns the first match |
g | Perform a global match and returns all matches |
m | Perform multiline match and returns the first match |
RegExp Brackets
The following table provides a list of all RegExp
brackets available in JavaScript.
Bracket | Explanation |
---|---|
[abc] | Finds any character(s) in/between the brackets |
[^abc] | Finds any character NOT in/between the brackets |
[0-9] | Finds any character (digit) in/between the brackets |
[^0-9] | Finds any character (digit) NOT in/between the brackets |
(x|y) | Find any of the alternatives specified |
RegExp Metacharacters
The following table provides a list of all RegExp
metacharacters available in JavaScript.
Metacharacter | Explanation |
---|---|
. | Matches any single character except the newline characters (\n, \r, etc.) |
\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 | Finds a match at the beginning or end of a word |
\B | Finds a match, but where it is NOT at the beginning/end of a word |
\0 | Finds a position (index value) of first occurrence of NUL character |
\n | Finds a position (index value) of first occurrence of newline character |
\f | Finds a position (index value) of first occurrence of form feed character |
\r | Finds a position (index value) of first occurrence of carriage return character |
\t | Finds a position (index value) of first occurrence of tab character |
\v | Finds a position (index value) of first occurrence of vertical tab character |
\ddd | Finds the Latin character specified by an octal number ddd |
\xdd | Finds the Latin character specified by a hexadecimal number dd |
\uxxxx | Finds the Unicode character specified by a hexadecimal number xxxx |
RegExp Quantifiers
The following table provides a list of all RegExp
quantifiers available in JavaScript.
Quantifier | Explanation |
---|---|
q+ | Matches any string that contains at least one q |
q* | Matches any string that contains zero or more occurrences of q |
q? | Matches any string that contains zero or one occurrences of q |
q{X} | Matches any string that contains a sequence of X q's |
q{X,Y} | Matches any string that contains a sequence of X to Y q's |
q{X,} | Matches any string that contains a sequence of at least X q's |
q$ | Matches any string with q at the end of it |
^q | Matches any string with n at the beginning of it |
?=q | Matches any string that is followed by a specific string q |
?!q | Matches any string that is not followed by a specific string q |
RegExp Properties
The following table provides a list of all RegExp
properties available in JavaScript.
Property | Explanation |
---|---|
Constructor | Returns the function that created the RegExp object's prototype |
global | Indicates whether the global match flag is specified or not |
ignoreCase | Indicates whether the case-insensitive match flag is specified or not |
lastIndex | Returns an integer that specifies the character position immediately following the last match |
multiline | Indicates whether the multiline match flag is specified or not |
source | Returns a string containing the source text of the regexp object |
RegExp Methods
The following table provides a list of all RegExp
methods available in JavaScript.
Method | Explanation |
---|---|
exec() | Tests for a match in a string and returns the first match |
test() | Tests for a match in a string and returns true or false |
toString() | Returns the string value of the regular expression |
Reminder
Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in JavaScript.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.