Created
February 10, 2019 20:52
-
-
Save ButlerFuqua/dade0c630ea50cae761efd109bee909e to your computer and use it in GitHub Desktop.
Reference for regular expression methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let re; | |
re = /hello/; | |
re = /hello/i; // i = case insensitive | |
// re = /hello/g; // Global search | |
// console.log(re); | |
// console.log(re.source); | |
// exec() - Return result in an array or null | |
// const result = re.exec(`hello world`); | |
// console.log(result); | |
// console.log(result[0]); | |
// console.log(result.index); | |
// console.log(result.input); | |
// test() - Returns true or false | |
// const result = re.test(`Hello`); | |
// console.log(result); | |
// match() = Return result array or null | |
// const str = `Hello There`; | |
// const result = str.match(re); | |
// console.log(result); | |
// search() - Return index of the first match. If not found, it returns -1 | |
// const str = `Butler, Hello There`; | |
// const result = str.search(re); | |
// console.log(result); | |
// replace() - Return new string with some or all matches of a pattern | |
// const str = `Hello There`; | |
// const newStr = str.replace(re, `Hi`); | |
// console.log(newStr); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment