RegExp
Overview
The RegExp
object in JavaScript provides powerful tools for pattern matching and text processing. It allows developers to define patterns for searching and manipulating strings, supporting modifiers such as global searches, case-insensitivity, and multiline matching. Key properties include the pattern source, flags indicating active modifiers, and the index position for the next match.
Core functionality includes the exec()
method, which searches for a pattern and returns the matched value while keeping track of the match position, and the test()
method, which checks if a pattern exists in a string, returning a boolean result.
For more information see: RegExp (MDN).
Properties Summarized
Methods Summarized
Properties Detailed
global
Specifies if the "g" modifier is set.
Type Boolean
Sample
ignoreCase
Specifies if the "i" modifier is set.
Type Boolean
Sample
lastIndex
An integer specifying the index at which to start the next match.
Type Number
Sample
multiline
Specifies if the "m" modifier is set.
Type Boolean
Sample
source
The text used for pattern matching.
Type String
Sample
Methods Detailed
exec(string)
Search a string for a specified value. Returns the found value and remembers the position.
Parameters
Object string ;
Returns: String A String representing the found value.
Sample
test(string)
Search a string for a specified value. Returns true or false.
Parameters
Object string ;
Returns: Boolean true if a match was found in the string. false otherwise.
Sample
Last updated