Javascript

Home Load Console Selectors CSS Form Strings If Else Array Reg Exp Date & Time setTimeout JSON Loops Objects Animation Fat Arrow Class Import IIFE undefined Tabulator.js ES6 Event Listeners AJAX Hide Elements Create Elements Checkbox ejs
O O

Weather Controls

Time Of Day
Rain
Wind Speed
Wind Direction
Clouds

Javascript : Reg Exp

2022-07-18

Regular Expressions

Match

Searches a string for a match against a regular expression and returns the matches as an Array. I'm not sure why anyone would use this if it just returns an array with identical values.

var str = "The rain in SPAIN stays mainly in the plain";
var res = str.match(/ain/g);
//returns: Array [ "ain", "ain", "ain" ]

Search

Its just like indexOf except it allows regular expressions. Returns -1 if no match is found.

var str = "I like pretty girls";
var n = str.search("pretty");
//returns 7