Using RegExp With Strings

suggest change

The String object has the following methods that accept regular expressions as arguments.

Match with RegExp

console.log("string".match(/[i-n]+/));
console.log("string".match(/(r)[i-n]+/));

Expected output

Array [“in”] Array [“rin”, “r”]

Replace with RegExp

console.log("string".replace(/[i-n]+/, "foo"));

Expected output

strfoog

Split with RegExp

console.log("stringstring".split(/[i-n]+/));

Expected output

Array [“str”, “gstr”, “g”]

Search with RegExp

.search() returns the index at which a match is found or -1.

console.log("string".search(/[i-n]+/));
console.log("string".search(/[o-q]+/));

Expected output

3 -1

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Regular Expression:
* Syntax
* Using RegExp With Strings

Table Of Contents
11 Arrays
12 Objects
14 Classes
16 Map
17 Set
24 Loops
27 Date
29 Scope
30 AJAX
32 Regular Expression
35 Cookies
41 JSON
44 Fetch
45 Modules
46 Screen
64 Console
68 Symbols
73 Modals
76 Events
86 Proxy
89 WeakMap
90 WeakSet
102 Tilde