JavaScript RegExp Object-Complete Reference

The RegExp Object The regular expression object describes a pattern of characters. Syntax for creating a RegExp object: var txt=...

The RegExp Object

The regular expression object describes a pattern of characters.

Syntax for creating a RegExp object:

var txt=new RegExp(pattern,attributes);
or
var txt=/pattern/attributes;
  • pattern specifies the pattern of the regular expression
  • attributes specifies global ("g"), case-insensitive ("i"), and multiline matches ("m")

RegExp Object Properties

FF: Firefox, N: Netscape, IE: Internet Explorer

Property Description FF N IE
global Specifies if the "g" modifier is set 1 4 4
ignoreCase Specifies if the "i" modifier is set 1 4 4
input The string on which the pattern match is performed 1 4 4
lastIndex An integer specifying the index at which to start the next match 1 4 4
lastMatch The last matched characters 1 4 4
lastParen The last matched parenthesized substring 1 4 4
leftContext The substring in front of the characters most recently matched 1 4 4
multiline Specifies if the "m" modifier is set 1 4 4
prototype Allows you to add properties and methods to the object 1 4 4
rightContext The substring after the characters most recently matched 1 4 4
source The text used for pattern matching 1 4 4

RegExp Object Methods

Method Description FF N IE
compile() Change the regular expression 1 4 4
exec() Search a string for a specified value. Returns the found value and remembers the position 1 4 4
test() Search a string for a specified value. Returns true or false 1 4 4

String Object Methods that supports Regular Expressions

Method Description FF N IE
search() Search a string for a specified value. Returns the position of the value 1 4 4
match() Search a string for a specified value. Returns an array of the found value(s) 1 4 4
replace() Replace characters with other characters 1 4 4
split() Split a string into an array of strings 1 4 4

RegExp Modifiers

Modifier Description FF N IE
i Perform case-insensitive matching 1 4 4
g Perform a global match. Find all matches (do not stop after the first match) 1 4 4
gi Perform a global case-insensitive match. Find all matches (do not stop after the first match) 1 4 4
m Perform multiline matching 1 4 4

RegExp Modifiers

Property Description FF N IE
Position Matching
^ Get a match at the beginning of a string 1 4 4
$ Get a match at the end of a string 1 4 4
\b Word boundary. Get a match at the beginning or end of a word in the string 1 4 4
\B Non-word boundary. Get a match when it is not at the beginning or end of a word in the string 1 4 4
?= A positive look ahead. Get a match if a string is followed by a specific string 1 4 4
?! A negative look ahead. Get a match if a string is not followed by a specific string 1 4 4

Literals
\0 Find a NULL character 1 4 4
\n Find a new line character 1 4 4
\f Find a form feed character 1 4 4
\r Find a carriage return character 1 4 4
\t Find a tab character 1 4 4
\v Find a vertical tab character 1 4 4
\xxx Find the ASCII character expressed by the octal number xxx 1 4 4
\xdd Find the ASCII character expressed by the hex number dd 1 4 4
\uxxxx Find the ASCII character expressed by the UNICODE xxxx 1 4 4

Character Classes
[xyz] Find any character in the specified character set 1 4 4
[^xyz] Find any character not in the specified character set 1 4 4
. (dot) Find any character except newline or line terminator 1 4 4
\w Find any alphanumeric character including the underscore 1 4 4
\W Find any non-word character 1 4 4
\d Find any single digit 1 4 4
\D Find any non-digit 1 4 4
\s Find any single space character 1 4 4
\S Find any single non-space character 1 4 4

Repetition
{x} Finds the exact (x) number of the regular expression grouped together 1 4 4
{x,} Finds the exact (x) or more number of the regular expression grouped together 1 4 4
{x,y} Finds between x and y number of the regular expression grouped together 1 4 4
? Finds zero or one occurrence of the regular expression 1 4 4
* Finds zero or more occurrences of the regular expression 1 4 4
+ Finds one or more occurrences of the regular expression 1 4 4

Grouping
( ) Finds the group of characters inside the parentheses and stores the matched string 1 4 4
(?: ) Finds the group of characters inside the parentheses but does not store the matched string  1 4 4
| Combines clauses into one regular expression and then matches any of the individual clauses. Similar to "OR" statement 1 4 4

Back references
( )\n Back reference. Uses the stored matched string. i.e. from the ( ) modifier 1 4 4
Name

ADO,131,ASP,3,C++,61,CORE JAVA,1,CSS,115,HTML,297,index,5,JAVASCRIPT,210,OS,47,PHP,65,SAD,53,SERVLETS,23,SOFTWARE ENGINEERING,245,SQL,71,TCP/IP,1,XHTML,9,XML,18,
ltr
item
Best Online Tutorials | Source codes | Programming Languages: JavaScript RegExp Object-Complete Reference
JavaScript RegExp Object-Complete Reference
Best Online Tutorials | Source codes | Programming Languages
https://www.1000sourcecodes.com/2012/05/javascript-regexp-object-complete.html
https://www.1000sourcecodes.com/
https://www.1000sourcecodes.com/
https://www.1000sourcecodes.com/2012/05/javascript-regexp-object-complete.html
true
357226456970214079
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content