Javascript RegExp Objects - Properties and Methods


  • In javascript, Regular expressions are used to perform pattern matches in strings.
  • Can be created by
  • i) Literal syntax. For example, to match 10 digit numbers : var mobileNumber = /\d{10}/.
  • ii)With RegExp constructor function. For example var mobileNumber = new RegExp("\\d{10}", "g").

Javascript RegExp Objects Property

specifies the function that creates an object's prototype.
Name Description Version
constructor Implemented in JavaScript 1.1
global Whether or not to test with the regular expression or not. Implemented in JavaScript 1.2
ignoreCase Whether case is to be ignored during pattern matching in a string Implemented in JavaScript 1.2
input The string against which a regular expression is matched. Implemented in JavaScript 1.2
lastIndex Specifies the index at which to start the next match. Implemented in JavaScript 1.2
lastMatch The last matched characters. Implemented in JavaScript 1.2
multiline Whether search in strings should be performed across multiple lines. Implemented in JavaScript 1.2
prototype Use to add new properties and methods to all instances of a class.
Implemented in JavaScript 1.1
rightContext The substring following the most recent match. Implemented in JavaScript 1.2
source A read-only property that contains the text of the pattern. Implemented in JavaScript 1.2

Javascript RegExp Objects Methods

Name Description Version
compile Use to execute the search for a match in a specified string. Implemented in JavaScript 1.2
exec Executes a search for a match in its string parameter. Implemented in JavaScript 1.2
test Executes a search for a match between a regular expression and a specified string Implemented in JavaScript 1.2
toSource Use to get a string representation (source code) of the object. Implemented in JavaScript 1.3
toString Represent the source code of the specified object. Implemented in JavaScript 1.1

Previous: JavaScript: Regular Expression
Next: JavaScript constructor Property: RegExp Object

JavaScript: Tips of the Day

Returns all unique values of an array, based on a provided comparator function


const tips_uniqueElementsBy = (arr, fn) =>
  arr.reduce((acc, v) => {
    if (!acc.some(x => fn(v, x))) acc.push(v);
    return acc;
  }, []);

    { id: 0, value: 'p' },
    { id: 1, value: 'q' },
    { id: 2, value: 'r' },
    { id: 1, value: 's' },
    { id: 0, value: 't' }
  (a, b) => a.id == b.id


[[object Object] {
  id: 0,
  value: "p"
}, [object Object] {
  id: 1,
  value: "q"
}, [object Object] {
  id: 2,
  value: "r"