Javascript RegExp Objects - Properties and Methods
Description
- 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
Name | Description | Version |
---|---|---|
constructor | specifies the function that creates an object's prototype. | 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
Test your Programming skills with w3resource's quiz.
JavaScript: Tips of the Day
Returns the first defined, non-null argument
Example:
const tips_coalesce = (...args) => args.find(v => ![undefined, null].includes(v)); console.log(tips_coalesce(null, undefined, '', NaN, 'Waldo'));
Output:
""
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework