JavaScript: String Method
Ruxin Qu
Posted on August 25, 2022
-
.search()
.match()
.replace()
with RegExp
- RegExp is a sequence of characters that form a search pattern. Syntax:
/pattern/modifiers;
. - Modifiers:
i
(perform case-insensitive match). Return the index of the first match.
.match(/char/g)
performs global match, doesn't stop after find the first matched. It will return an array containing all the matching result.
m
(perform multiline matching)
-
.search()
and.replace()
are case-sensitive, adding RegExp can make it case-insensitive.
2.
const first = string.indexOf(searchString)
const second = string.indexOf(searchString, (first +1));
//starts from the position after the first index
3..split()
const str = 'ssss=dddd';
const back = str.split('=')[1];
console.log(back). //output: 'dddd'
console.log(str.split('')) //output: [
's', 's', 's',
's', '=', 'd',
'd', 'd', 'd'
]
💖 💪 🙅 🚩
Ruxin Qu
Posted on August 25, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
webdev A Tale of WeakMap and WeakSet in JavaScript: The Guardians of Forgotten Secrets
November 29, 2024