Skip to content

Instantly share code, notes, and snippets.

@ButlerFuqua
Created February 10, 2019 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ButlerFuqua/dade0c630ea50cae761efd109bee909e to your computer and use it in GitHub Desktop.
Save ButlerFuqua/dade0c630ea50cae761efd109bee909e to your computer and use it in GitHub Desktop.
Reference for regular expression methods
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