Animations

API

Arrays

Async

Basics

Challenges

Classes

Console

Dates

Debugging

DOM Elements

DOM Methods

DOM Navigation

DOM Properties

Event Listeners

Flow Control

Forms

Functions

Global Functions

JSON

Keywords

Libraries (3rd party)

Math

Modules

Objects

Snippets

String

Types

Widgets

Window Object

JavaScript - RegEx Basics

A regular expression is a sequence of characters that forms a search pattern. The search pattern can be used for text search and text replace operations. When you search for data in a text, you can use this search pattern to describe what you are searching for. A regular expression can be a single character, or a more complicated pattern.

A regular expression is expressed between two forward slashes:


/[expression]/

// syntax
/pattern/modifiers;

// example
var patt = /w3schools/i;
    

Example explained:

/w3schools/i is a regular expression. w3schools is a pattern (to be used in a search). i is a modifier (modifies the search to be case-insensitive).

The pattern cannot be defined as a string. Use this x.search(/w3schools/i) and NOT this x.search('/w3schools/1');

https://www.w3schools.com/js/js_regexp.asp

http://buildregex.com/

https://www.regexbuddy.com/create.html